1
1
import { addFilter } from '@wordpress/hooks' ;
2
- import { useCallback , useMemo , useEffect , useState } from '@wordpress/element' ;
2
+ import { useCallback , useMemo , useState } from '@wordpress/element' ;
3
3
import { __ } from '@wordpress/i18n' ;
4
4
import { createHigherOrderComponent } from '@wordpress/compose' ;
5
5
import { InspectorControls } from '@wordpress/block-editor' ;
@@ -14,29 +14,19 @@ import {
14
14
FlexBlock ,
15
15
FlexItem ,
16
16
} from '@wordpress/components' ;
17
- import { useSelect , useDispatch } from '@wordpress/data' ;
18
- import { store as editorStore } from '@wordpress/editor' ;
17
+ import { useSelect } from '@wordpress/data' ;
19
18
import { store as blocksStore } from '@wordpress/blocks' ;
20
19
import { useEntityProp } from '@wordpress/core-data' ;
21
20
22
21
import ManageBindings from './_manage-bindings' ;
23
22
24
23
import SUPPORTED_BLOCK_ATTRIBUTES from './_supported-attributes' ;
25
24
26
- const ErrorMessage = ( { children } ) => {
27
- return (
28
- < span style = { { color : 'var(--wp--preset--color--vivid-red)' } } >
29
- { children }
30
- </ span >
31
- ) ;
32
- } ;
33
-
34
25
const withAttributeBinder = createHigherOrderComponent ( ( BlockEdit ) => {
35
26
return ( props ) => {
36
27
const { getBlockType } = useSelect ( blocksStore ) ;
37
28
const { getBlockParentsByBlockName, getBlocksByClientId } =
38
29
useSelect ( 'core/block-editor' ) ;
39
- const { lockPostSaving, unlockPostSaving } = useDispatch ( editorStore ) ;
40
30
const [ editingBoundAttribute , setEditingBoundAttribute ] =
41
31
useState ( null ) ;
42
32
@@ -57,12 +47,6 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
57
47
( field ) => field . slug === attributes . metadata ?. slug
58
48
) ;
59
49
60
- const getBinding = useCallback (
61
- ( attribute ) =>
62
- attributes . metadata ?. [ window . BINDINGS_KEY ] ?. [ attribute ] ,
63
- [ attributes . metadata ]
64
- ) ;
65
-
66
50
const removeBindings = useCallback ( ( ) => {
67
51
const newAttributes = {
68
52
metadata : {
@@ -137,63 +121,6 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
137
121
[ attributes . metadata , setAttributes , supportedAttributes ]
138
122
) ;
139
123
140
- const validations = useMemo ( ( ) => {
141
- const metadata = attributes . metadata ?? { } ;
142
- const bindings = metadata [ window . BINDINGS_KEY ] ?? { } ;
143
-
144
- const _validations = { } ;
145
-
146
- const hasAtLeastOneBinding = Object . keys ( bindings ) . length > 0 ;
147
-
148
- if (
149
- hasAtLeastOneBinding &&
150
- ! metadata [ window . BLOCK_VARIATION_NAME_ATTR ]
151
- ) {
152
- _validations [ window . BLOCK_VARIATION_NAME_ATTR ] = (
153
- < ErrorMessage >
154
- { __ ( 'Block variation name is required' ) }
155
- </ ErrorMessage >
156
- ) ;
157
- }
158
-
159
- if (
160
- metadata [ window . BLOCK_VARIATION_NAME_ATTR ] &&
161
- ! hasAtLeastOneBinding
162
- ) {
163
- _validations [ window . BLOCK_VARIATION_NAME_ATTR ] = (
164
- < ErrorMessage >
165
- { __ ( 'Bind at least one attribute' ) }
166
- </ ErrorMessage >
167
- ) ;
168
- }
169
-
170
- Object . keys ( bindings ) . forEach ( ( attribute ) => {
171
- const field = getBinding ( attribute ) ;
172
-
173
- if ( field === 'post_content' && name !== 'core/group' ) {
174
- _validations [ attribute ] = (
175
- < ErrorMessage >
176
- { __ (
177
- 'Only Group blocks can be bound to post_content'
178
- ) }
179
- </ ErrorMessage >
180
- ) ;
181
- }
182
- } ) ;
183
-
184
- return _validations ;
185
- } , [ attributes . metadata , getBinding , name ] ) ;
186
-
187
- useEffect ( ( ) => {
188
- const hasValidationErrors = Object . keys ( validations ) . length > 0 ;
189
-
190
- if ( hasValidationErrors ) {
191
- lockPostSaving ( ) ;
192
- } else {
193
- unlockPostSaving ( ) ;
194
- }
195
- } , [ lockPostSaving , unlockPostSaving , validations ] ) ;
196
-
197
124
if ( ! supportedAttributes || parentHasBindings ) {
198
125
return < BlockEdit { ...props } /> ;
199
126
}
0 commit comments