From 13839fd5f7320a8436412c6f657a27cccb079356 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Fri, 9 Feb 2024 12:29:59 +0100 Subject: [PATCH 1/6] Lock editing by default when bindings exist --- packages/block-editor/src/components/rich-text/index.js | 3 ++- packages/block-library/src/button/edit.js | 2 +- packages/block-library/src/image/edit.js | 2 +- packages/block-library/src/image/image.js | 6 +++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index f45cc618d4547e..f5814daa0ff393 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -161,7 +161,8 @@ export function RichTextWrapper( if ( blockTypeAttributes?.[ attribute ]?.source === 'rich-text' && - getBlockBindingsSource( args.source )?.lockAttributesEditing + getBlockBindingsSource( args.source ) + ?.lockAttributesEditing !== false ) { shouldDisableEditing = true; break; diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index c3a2aff1bd0d9f..40144e685c30dc 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -246,7 +246,7 @@ function ButtonEdit( props ) { lockUrlControls: !! metadata?.bindings?.url && getBlockBindingsSource( metadata?.bindings?.url?.source ) - ?.lockAttributesEditing === true, + ?.lockAttributesEditing !== false, }; }, [ isSelected ] diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 63b99460b386af..ae6ae1f14168db 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -349,7 +349,7 @@ export function ImageEdit( { lockUrlControls: !! metadata?.bindings?.url && getBlockBindingsSource( metadata?.bindings?.url?.source ) - ?.lockAttributesEditing === true, + ?.lockAttributesEditing !== false, }; }, [ isSingleSelected ] diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index 8c911fad726aed..2924c9d8454d5e 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -427,7 +427,7 @@ export default function Image( { lockUrlControls: !! urlBinding && getBlockBindingsSource( urlBinding?.source ) - ?.lockAttributesEditing === true, + ?.lockAttributesEditing !== false, 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. @@ -435,11 +435,11 @@ export default function Image( { lockAltControls: !! altBinding && getBlockBindingsSource( altBinding?.source ) - ?.lockAttributesEditing === true, + ?.lockAttributesEditing !== false, lockTitleControls: !! titleBinding && getBlockBindingsSource( titleBinding?.source ) - ?.lockAttributesEditing === true, + ?.lockAttributesEditing !== false, }; }, [ clientId, isSingleSelected, metadata?.bindings ] From dc9da5caea67ca9dbb1bccaaa0fed86319b6ffb1 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Fri, 9 Feb 2024 12:29:59 +0100 Subject: [PATCH 2/6] Use default in post meta source --- packages/editor/src/bindings/post-meta.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/editor/src/bindings/post-meta.js b/packages/editor/src/bindings/post-meta.js index 091491b2ed00c7..580891b8f6dfe7 100644 --- a/packages/editor/src/bindings/post-meta.js +++ b/packages/editor/src/bindings/post-meta.js @@ -38,5 +38,4 @@ export default { useValue: [ metaValue, updateMetaValue ], }; }, - lockAttributesEditing: true, }; From fd32d62cc1ec0a07aad4d83fb30cfacf0c135a15 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Fri, 9 Feb 2024 12:29:59 +0100 Subject: [PATCH 3/6] Set `lockEditing` to false in pattern overrides --- .../block-editor/src/hooks/use-bindings-attributes.js | 2 +- packages/editor/src/bindings/index.js | 2 ++ packages/editor/src/bindings/pattern-overrides.js | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 packages/editor/src/bindings/pattern-overrides.js diff --git a/packages/block-editor/src/hooks/use-bindings-attributes.js b/packages/block-editor/src/hooks/use-bindings-attributes.js index a1873143c294af..75f337cff97957 100644 --- a/packages/block-editor/src/hooks/use-bindings-attributes.js +++ b/packages/block-editor/src/hooks/use-bindings-attributes.js @@ -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, diff --git a/packages/editor/src/bindings/index.js b/packages/editor/src/bindings/index.js index 8a883e8904a71b..ff0516902e321c 100644 --- a/packages/editor/src/bindings/index.js +++ b/packages/editor/src/bindings/index.js @@ -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 ); diff --git a/packages/editor/src/bindings/pattern-overrides.js b/packages/editor/src/bindings/pattern-overrides.js new file mode 100644 index 00000000000000..a2b2107b5e4510 --- /dev/null +++ b/packages/editor/src/bindings/pattern-overrides.js @@ -0,0 +1,11 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + +export default { + name: 'core/pattern-overrides', + label: __( 'Pattern Overrides' ), + useSource: null, + lockAttributesEditing: false, +}; From 79a42c5608482e10b6ba7c2d193e5fd637028d5c Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Fri, 9 Feb 2024 12:36:55 +0100 Subject: [PATCH 4/6] Move default value to reducer --- packages/block-editor/src/components/rich-text/index.js | 3 +-- packages/block-editor/src/store/reducer.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 +++--- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index f5814daa0ff393..f45cc618d4547e 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -161,8 +161,7 @@ export function RichTextWrapper( if ( blockTypeAttributes?.[ attribute ]?.source === 'rich-text' && - getBlockBindingsSource( args.source ) - ?.lockAttributesEditing !== false + getBlockBindingsSource( args.source )?.lockAttributesEditing ) { shouldDisableEditing = true; break; diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index d4755169c53e56..0be421b757bce1 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -2057,7 +2057,7 @@ function blockBindingsSources( state = {}, action ) { [ action.sourceName ]: { label: action.sourceLabel, useSource: action.useSource, - lockAttributesEditing: action.lockAttributesEditing, + lockAttributesEditing: action.lockAttributesEditing ?? true, }, }; } diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index 40144e685c30dc..e01898ca00dec4 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -246,7 +246,7 @@ function ButtonEdit( props ) { lockUrlControls: !! metadata?.bindings?.url && getBlockBindingsSource( metadata?.bindings?.url?.source ) - ?.lockAttributesEditing !== false, + ?.lockAttributesEditing, }; }, [ isSelected ] diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index ae6ae1f14168db..61d023e4e580a1 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -349,7 +349,7 @@ export function ImageEdit( { lockUrlControls: !! metadata?.bindings?.url && getBlockBindingsSource( metadata?.bindings?.url?.source ) - ?.lockAttributesEditing !== false, + ?.lockAttributesEditing, }; }, [ isSingleSelected ] diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index 2924c9d8454d5e..f551d8df007a8e 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -427,7 +427,7 @@ export default function Image( { lockUrlControls: !! urlBinding && getBlockBindingsSource( urlBinding?.source ) - ?.lockAttributesEditing !== false, + ?.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. @@ -435,11 +435,11 @@ export default function Image( { lockAltControls: !! altBinding && getBlockBindingsSource( altBinding?.source ) - ?.lockAttributesEditing !== false, + ?.lockAttributesEditing, lockTitleControls: !! titleBinding && getBlockBindingsSource( titleBinding?.source ) - ?.lockAttributesEditing !== false, + ?.lockAttributesEditing, }; }, [ clientId, isSingleSelected, metadata?.bindings ] From 228c14277b04360a45c9bb5a203c85a834c0d958 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Fri, 9 Feb 2024 12:41:19 +0100 Subject: [PATCH 5/6] Use `_x` for sources translations --- packages/editor/src/bindings/pattern-overrides.js | 4 ++-- packages/editor/src/bindings/post-meta.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/bindings/pattern-overrides.js b/packages/editor/src/bindings/pattern-overrides.js index a2b2107b5e4510..dca76005587701 100644 --- a/packages/editor/src/bindings/pattern-overrides.js +++ b/packages/editor/src/bindings/pattern-overrides.js @@ -1,11 +1,11 @@ /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; +import { _x } from '@wordpress/i18n'; export default { name: 'core/pattern-overrides', - label: __( 'Pattern Overrides' ), + label: _x( 'Pattern Overrides' ), useSource: null, lockAttributesEditing: false, }; diff --git a/packages/editor/src/bindings/post-meta.js b/packages/editor/src/bindings/post-meta.js index 580891b8f6dfe7..a37125b8e0a2a3 100644 --- a/packages/editor/src/bindings/post-meta.js +++ b/packages/editor/src/bindings/post-meta.js @@ -3,7 +3,7 @@ */ import { useEntityProp } from '@wordpress/core-data'; import { useSelect } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; +import { _x } from '@wordpress/i18n'; /** * Internal dependencies */ @@ -11,7 +11,7 @@ import { store as editorStore } from '../store'; export default { name: 'core/post-meta', - label: __( 'Post Meta' ), + label: _x( 'Post Meta' ), useSource( props, sourceAttributes ) { const { getCurrentPostType } = useSelect( editorStore ); const { context } = props; From 653a477f06cf7456002dcd50df5a36c92c55d9df Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Fri, 9 Feb 2024 14:11:03 +0100 Subject: [PATCH 6/6] Add context to translations --- packages/editor/src/bindings/pattern-overrides.js | 2 +- packages/editor/src/bindings/post-meta.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/bindings/pattern-overrides.js b/packages/editor/src/bindings/pattern-overrides.js index dca76005587701..5f7f475a649a3e 100644 --- a/packages/editor/src/bindings/pattern-overrides.js +++ b/packages/editor/src/bindings/pattern-overrides.js @@ -5,7 +5,7 @@ import { _x } from '@wordpress/i18n'; export default { name: 'core/pattern-overrides', - label: _x( 'Pattern Overrides' ), + label: _x( 'Pattern Overrides', 'block bindings source' ), useSource: null, lockAttributesEditing: false, }; diff --git a/packages/editor/src/bindings/post-meta.js b/packages/editor/src/bindings/post-meta.js index a37125b8e0a2a3..a9a00599b68037 100644 --- a/packages/editor/src/bindings/post-meta.js +++ b/packages/editor/src/bindings/post-meta.js @@ -11,7 +11,7 @@ import { store as editorStore } from '../store'; export default { name: 'core/post-meta', - label: _x( 'Post Meta' ), + label: _x( 'Post Meta', 'block bindings source' ), useSource( props, sourceAttributes ) { const { getCurrentPostType } = useSelect( editorStore ); const { context } = props;