diff --git a/docs/designers-developers/developers/block-api/block-registration.md b/docs/designers-developers/developers/block-api/block-registration.md index cab91e38c1de4f..432c6941eec404 100644 --- a/docs/designers-developers/developers/block-api/block-registration.md +++ b/docs/designers-developers/developers/block-api/block-registration.md @@ -259,6 +259,7 @@ An object describing a variation defined for the block type can contain the foll - `name` (type `string`) – The unique and machine-readable name. - `title` (type `string`) – A human-readable variation title. - `description` (optional, type `string`) – A detailed variation description. +- `category` (optional, type `string`) - A category classification, used in search interfaces to arrange block types by category. - `icon` (optional, type `string` | `Object`) – An icon helping to visualize the variation. It can have the same shape as the block type. - `isDefault` (optional, type `boolean`) – Indicates whether the current variation is the default one. Defaults to `false`. - `attributes` (optional, type `Object`) – Values that override block attributes. diff --git a/packages/block-editor/src/components/inserter/search-items.js b/packages/block-editor/src/components/inserter/search-items.js index dda44c44fe90cc..a896ba857a682a 100644 --- a/packages/block-editor/src/components/inserter/search-items.js +++ b/packages/block-editor/src/components/inserter/search-items.js @@ -71,19 +71,6 @@ export const searchBlockItems = ( find( categories, { slug: item.category } )?.title, getCollection: ( item ) => collections[ item.name.split( '/' )[ 0 ] ]?.title, - getVariations: ( { variations = [] } ) => - Array.from( - variations.reduce( - ( accumulator, { title, keywords = [] } ) => { - accumulator.add( title ); - keywords.forEach( ( keyword ) => - accumulator.add( keyword ) - ); - return accumulator; - }, - new Set() - ) - ), }; return searchItems( items, searchInput, config ); diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index dc9f27cfb3d066..921c8cd03b40be 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1402,6 +1402,7 @@ const getItemFromVariation = ( item ) => ( variation ) => ( { icon: variation.icon || item.icon, title: variation.title || item.title, description: variation.description || item.description, + category: variation.category || item.category, // If `example` is explicitly undefined for the variation, the preview will not be shown. example: variation.hasOwnProperty( 'example' ) ? variation.example diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index 7c1ce2c1643384..8aa2f025410adf 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -82,6 +82,9 @@ import { store as blocksStore } from '../store'; * @property {string} name The unique and machine-readable name. * @property {string} title A human-readable variation title. * @property {string} [description] A detailed variation description. + * @property {string} [category] Block type category classification, + * used in search interfaces to arrange + * block types by category. * @property {WPIcon} [icon] An icon helping to visualize the variation. * @property {boolean} [isDefault] Indicates whether the current variation is * the default one. Defaults to `false`.