diff --git a/packages/block-editor/src/components/inserter/search-items.js b/packages/block-editor/src/components/inserter/search-items.js index 6eb910d33df7fa..7af0ede8a253c1 100644 --- a/packages/block-editor/src/components/inserter/search-items.js +++ b/packages/block-editor/src/components/inserter/search-items.js @@ -57,7 +57,7 @@ export const searchItems = ( items, categories, searchTerm ) => { return items; } - return items.filter( ( { title, category, keywords = [] } ) => { + return items.filter( ( { title, category, keywords = [], patterns = [] } ) => { let unmatchedTerms = removeMatchingTerms( normalizedTerms, title @@ -81,6 +81,15 @@ export const searchItems = ( items, categories, searchTerm ) => { get( find( categories, { slug: category } ), [ 'title' ] ), ); + if ( unmatchedTerms.length === 0 ) { + return true; + } + + unmatchedTerms = removeMatchingTerms( + unmatchedTerms, + patterns.map( ( { label } ) => label ).join( ' ' ), + ); + return unmatchedTerms.length === 0; } ); }; diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index ba6b808fb44136..4e591081b675f4 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1264,6 +1264,7 @@ export const getInserterItems = createSelector( icon: blockType.icon, category: blockType.category, keywords: blockType.keywords, + patterns: blockType.patterns, isDisabled, utility: calculateUtility( blockType.category, count, isContextual ), frecency: calculateFrecency( time, count ), diff --git a/packages/blocks/src/store/selectors.js b/packages/blocks/src/store/selectors.js index 8e07052ad55844..16a8fa6c7c708a 100644 --- a/packages/blocks/src/store/selectors.js +++ b/packages/blocks/src/store/selectors.js @@ -37,9 +37,17 @@ const getNormalizedBlockType = ( state, nameOrType ) => ( * @return {Array} Block Types. */ export const getBlockTypes = createSelector( - ( state ) => Object.values( state.blockTypes ), + ( state ) => { + return Object.values( state.blockTypes ).map( ( blockType ) => { + return { + ...blockType, + patterns: __experimentalGetBlockPatterns( state, blockType.name ), + }; + } ); + }, ( state ) => [ state.blockTypes, + state.blockPatterns, ] );