@@ -16,7 +16,6 @@ import {
16
16
import { createHigherOrderComponent , useInstanceId } from '@wordpress/compose' ;
17
17
import { addFilter } from '@wordpress/hooks' ;
18
18
import { useMemo , useEffect } from '@wordpress/element' ;
19
- import { useDispatch } from '@wordpress/data' ;
20
19
21
20
/**
22
21
* Internal dependencies
@@ -34,12 +33,10 @@ import {
34
33
} from '../components/duotone/utils' ;
35
34
import { getBlockCSSSelector } from '../components/global-styles/get-block-css-selector' ;
36
35
import { scopeSelector } from '../components/global-styles/utils' ;
37
- import { useBlockSettings } from './utils' ;
36
+ import { useBlockSettings , useStyleOverride } from './utils' ;
38
37
import { default as StylesFiltersPanel } from '../components/global-styles/filters-panel' ;
39
38
import { useBlockEditingMode } from '../components/block-editing-mode' ;
40
39
import { __unstableUseBlockElement as useBlockElement } from '../components/block-list/use-block-props/use-block-refs' ;
41
- import { store as blockEditorStore } from '../store' ;
42
- import { unlock } from '../lock-unlock' ;
43
40
44
41
const EMPTY_ARRAY = [ ] ;
45
42
@@ -291,28 +288,34 @@ function DuotoneStyles( {
291
288
292
289
const isValidFilter = Array . isArray ( colors ) || colors === 'unset' ;
293
290
294
- const { setStyleOverride, deleteStyleOverride } = unlock (
295
- useDispatch ( blockEditorStore )
291
+ useStyleOverride (
292
+ isValidFilter
293
+ ? {
294
+ css :
295
+ colors !== 'unset'
296
+ ? getDuotoneStylesheet ( selector , filterId )
297
+ : getDuotoneUnsetStylesheet ( selector ) ,
298
+ __unstableType : 'presets' ,
299
+ }
300
+ : undefined
301
+ ) ;
302
+ useStyleOverride (
303
+ isValidFilter
304
+ ? {
305
+ assets :
306
+ colors !== 'unset'
307
+ ? getDuotoneFilter ( filterId , colors )
308
+ : '' ,
309
+ __unstableType : 'svgs' ,
310
+ }
311
+ : undefined
296
312
) ;
297
313
298
314
const blockElement = useBlockElement ( clientId ) ;
299
315
300
316
useEffect ( ( ) => {
301
317
if ( ! isValidFilter ) return ;
302
318
303
- setStyleOverride ( filterId , {
304
- css :
305
- colors !== 'unset'
306
- ? getDuotoneStylesheet ( selector , filterId )
307
- : getDuotoneUnsetStylesheet ( selector ) ,
308
- __unstableType : 'presets' ,
309
- } ) ;
310
- setStyleOverride ( `duotone-${ filterId } ` , {
311
- assets :
312
- colors !== 'unset' ? getDuotoneFilter ( filterId , colors ) : '' ,
313
- __unstableType : 'svgs' ,
314
- } ) ;
315
-
316
319
// Safari does not always update the duotone filter when the duotone colors
317
320
// are changed. When using Safari, force the block element to be repainted by
318
321
// the browser to ensure any changes are reflected visually. This logic matches
@@ -329,20 +332,7 @@ function DuotoneStyles( {
329
332
blockElement . offsetHeight ;
330
333
blockElement . style . display = display ;
331
334
}
332
-
333
- return ( ) => {
334
- deleteStyleOverride ( filterId ) ;
335
- deleteStyleOverride ( `duotone-${ filterId } ` ) ;
336
- } ;
337
- } , [
338
- isValidFilter ,
339
- blockElement ,
340
- colors ,
341
- selector ,
342
- filterId ,
343
- setStyleOverride ,
344
- deleteStyleOverride ,
345
- ] ) ;
335
+ } , [ isValidFilter , blockElement ] ) ;
346
336
347
337
return null ;
348
338
}
0 commit comments