|
1 | 1 | import { v4 as uuid } from 'uuid'; |
2 | | -import { createHooks, applyFilters } from '@wordpress/hooks'; |
| 2 | +import { applyFilters } from '@wordpress/hooks'; |
3 | 3 | import deprecated from '@wordpress/deprecated'; |
4 | 4 | import warning from '@wordpress/warning'; |
5 | 5 | import { |
@@ -460,24 +460,12 @@ export function findTransform< T extends BlockTransform >( |
460 | 460 | transforms: T[], |
461 | 461 | predicate: ( transform: T ) => boolean |
462 | 462 | ): T | null { |
463 | | - // The hooks library already has built-in mechanisms for managing priority |
464 | | - // queue, so leverage via locally-defined instance. |
465 | | - const hooks = createHooks(); |
466 | | - |
467 | | - for ( let i = 0; i < transforms.length; i++ ) { |
468 | | - const candidate = transforms[ i ]; |
469 | | - if ( predicate( candidate ) ) { |
470 | | - hooks.addFilter( |
471 | | - 'transform', |
472 | | - 'transform/' + i.toString(), |
473 | | - ( result ) => ( result ? result : candidate ), |
474 | | - candidate.priority |
475 | | - ); |
476 | | - } |
477 | | - } |
478 | | - |
479 | | - // Filter name is arbitrarily chosen but consistent with above aggregation. |
480 | | - return hooks.applyFilters( 'transform', null ) as T | null; |
| 463 | + // `priority` has the same meaning as in WP hooks: lower runs earlier, default is 10. |
| 464 | + const priority = ( t: T ) => t.priority ?? 10; |
| 465 | + const candidates = transforms |
| 466 | + .filter( ( t ) => predicate( t ) ) |
| 467 | + .toSorted( ( t1, t2 ) => priority( t1 ) - priority( t2 ) ); |
| 468 | + return candidates.length > 0 ? candidates[ 0 ] : null; |
481 | 469 | } |
482 | 470 |
|
483 | 471 | /** |
|
0 commit comments