@@ -25,6 +25,8 @@ import { store as editorStore } from '@wordpress/editor';
25
25
*/
26
26
import BlockAttributesControlLinkedButton from './components/block-attributes-control-linked-button' ;
27
27
28
+ // These constant and the function above have been copied from Gutenberg. It should be public, eventually.
29
+
28
30
const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
29
31
'core/paragraph' : [ 'content' ] ,
30
32
'core/heading' : [ 'content' ] ,
@@ -49,6 +51,7 @@ function getBindableAttributes( blockName ) {
49
51
const withCustomControls = createHigherOrderComponent ( ( BlockEdit ) => {
50
52
return ( props ) => {
51
53
const bindableAttributes = getBindableAttributes ( props . name ) ;
54
+ const showLinkedButton = props . name === 'core/image' ;
52
55
const { updateBlockBindings, removeAllBlockBindings } =
53
56
useBlockBindingsUtils ( ) ;
54
57
@@ -81,7 +84,6 @@ const withCustomControls = createHigherOrderComponent( ( BlockEdit ) => {
81
84
82
85
const currentBindings = props . attributes ?. metadata ?. bindings || { } ;
83
86
84
- // Memoize the fields transformation to prevent unnecessary recalculations
85
87
const fields = useMemo (
86
88
( ) =>
87
89
fieldsGroups ?. reduce ( ( acc , fieldGroup ) => {
@@ -98,7 +100,7 @@ const withCustomControls = createHigherOrderComponent( ( BlockEdit ) => {
98
100
} , [ ] ) || [ ] ,
99
101
[ fieldsGroups ]
100
102
) ;
101
- // Memoize the fieldsSuggestions to avoid recreating on every render
103
+
102
104
const fieldsSuggestions = useMemo ( ( ) => {
103
105
if ( props . name === 'core/image' ) {
104
106
// return only the type image fields
@@ -151,7 +153,7 @@ const withCustomControls = createHigherOrderComponent( ( BlockEdit ) => {
151
153
// Memoize the change handler to prevent creating new function on each render
152
154
const handleFieldChange = useCallback (
153
155
( attributes , value ) => {
154
- // Ensure attributes is always an array
156
+ // Ensure attributes is always an array.
155
157
const attributeArray = Array . isArray ( attributes )
156
158
? attributes
157
159
: [ attributes ] ;
@@ -171,7 +173,7 @@ const withCustomControls = createHigherOrderComponent( ( BlockEdit ) => {
171
173
} ;
172
174
} ) ;
173
175
174
- // Update all bindings at once
176
+ // Update all bindings at once.
175
177
updateBlockBindings ( bindings ) ;
176
178
177
179
return newState ;
@@ -195,7 +197,6 @@ const withCustomControls = createHigherOrderComponent( ( BlockEdit ) => {
195
197
[ updateBlockBindings ]
196
198
) ;
197
199
198
- // Handle reset for ToolsPanel
199
200
const handleReset = useCallback ( ( ) => {
200
201
removeAllBlockBindings ( ) ;
201
202
setBoundFields ( { } ) ;
@@ -216,7 +217,7 @@ const withCustomControls = createHigherOrderComponent( ( BlockEdit ) => {
216
217
) }
217
218
resetAll = { handleReset }
218
219
>
219
- { 'core/image' === props . name && (
220
+ { showLinkedButton && (
220
221
< HStack
221
222
justify = "space-between"
222
223
align = "center"
@@ -335,7 +336,6 @@ const withCustomControls = createHigherOrderComponent( ( BlockEdit ) => {
335
336
} ;
336
337
} , 'withCustomControls' ) ;
337
338
338
- // Only register the filter if the connect_fields beta feature is enabled
339
339
if ( window . scf ?. betaFeatures ?. connect_fields ) {
340
340
addFilter (
341
341
'editor.BlockEdit' ,
0 commit comments