From e63294c505486610909f4395971f1aa6513260a8 Mon Sep 17 00:00:00 2001 From: Nik Tsekouras Date: Fri, 26 Nov 2021 13:13:10 +0200 Subject: [PATCH] [Inserter]: Adjust order of theme blocks and reorder inserter items (#36719) * [Inserter]: Prioritize blocks per category in main inserter * change block categories to `theme` * Revert "[Inserter]: Prioritize blocks per category in main inserter" * reorder blocks and make variations appear right after their source block * register Navigation block earlier * reorder blocks --- packages/block-editor/src/store/selectors.js | 40 +++++--------- packages/block-library/src/index.js | 52 ++++++++++--------- .../block-library/src/post-terms/block.json | 2 +- .../block-library/src/query-title/block.json | 2 +- .../block-library/src/site-logo/block.json | 2 +- .../block-library/src/site-tagline/block.json | 2 +- .../block-library/src/site-title/block.json | 2 +- 7 files changed, 46 insertions(+), 56 deletions(-) diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 0aec0c679113..68e06da5d3e3 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1643,22 +1643,19 @@ export const getInserterItems = createSelector( ? getReusableBlocks( state ).map( buildReusableBlockInserterItem ) : []; - // Exclude any block type item that is to be replaced by a default - // variation. - const visibleBlockTypeInserterItems = blockTypeInserterItems.filter( - ( { variations = [] } ) => - ! variations.some( ( { isDefault } ) => isDefault ) - ); - - const blockVariations = []; - // Show all available blocks with variations - for ( const item of blockTypeInserterItems ) { + const items = blockTypeInserterItems.reduce( ( accumulator, item ) => { const { variations = [] } = item; + // Exclude any block type item that is to be replaced by a default variation + if ( ! variations.some( ( { isDefault } ) => isDefault ) ) { + accumulator.push( item ); + } if ( variations.length ) { const variationMapper = getItemFromVariation( state, item ); - blockVariations.push( ...variations.map( variationMapper ) ); + accumulator.push( ...variations.map( variationMapper ) ); } - } + return accumulator; + }, [] ); + // Ensure core blocks are prioritized in the returned results, // because third party blocks can be registered earlier than // the core blocks (usually by using the `init` action), @@ -1671,20 +1668,11 @@ export const getInserterItems = createSelector( type.push( block ); return blocks; }; - const items = visibleBlockTypeInserterItems.reduce( groupByType, { - core: [], - noncore: [], - } ); - const variations = blockVariations.reduce( groupByType, { - core: [], - noncore: [], - } ); - const sortedBlockTypes = [ - ...items.core, - ...variations.core, - ...items.noncore, - ...variations.noncore, - ]; + const { + core: coreItems, + noncore: nonCoreItems, + } = items.reduce( groupByType, { core: [], noncore: [] } ); + const sortedBlockTypes = [ ...coreItems, ...nonCoreItems ]; return [ ...sortedBlockTypes, ...reusableBlockInserterItems ]; }, ( state, rootClientId ) => [ diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index a2476fc0de97..0f445ac78424 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -149,53 +149,55 @@ export const __experimentalGetCoreBlocks = () => [ html, latestComments, latestPosts, - logInOut, mediaText, missing, more, - navigation, - navigationLink, - navigationSubmenu, nextpage, pageList, pattern, - postAuthor, - postComments, - postContent, - postDate, - postExcerpt, - postFeaturedImage, - postNavigationLink, - postTemplate, - postTerms, - postTitle, preformatted, pullquote, - query, - queryPagination, - queryPaginationNext, - queryPaginationNumbers, - queryPaginationPrevious, - queryTitle, reusableBlock, rss, search, separator, shortcode, - siteLogo, - siteTagline, - siteTitle, socialLink, socialLinks, spacer, table, // tableOfContents, tagCloud, - templatePart, - termDescription, textColumns, verse, video, + + // theme blocks + navigation, + navigationLink, + navigationSubmenu, + siteLogo, + siteTitle, + siteTagline, + query, + templatePart, + postTitle, + postExcerpt, + postFeaturedImage, + postContent, + postAuthor, + postDate, + postTerms, + postNavigationLink, + postTemplate, + queryPagination, + queryPaginationNext, + queryPaginationNumbers, + queryPaginationPrevious, + postComments, + logInOut, + termDescription, + queryTitle, ]; /** diff --git a/packages/block-library/src/post-terms/block.json b/packages/block-library/src/post-terms/block.json index 2ca14e6a92db..0f24ef9643f7 100644 --- a/packages/block-library/src/post-terms/block.json +++ b/packages/block-library/src/post-terms/block.json @@ -3,7 +3,7 @@ "apiVersion": 2, "name": "core/post-terms", "title": "Post Terms", - "category": "design", + "category": "theme", "description": "Post terms.", "textdomain": "default", "attributes": { diff --git a/packages/block-library/src/query-title/block.json b/packages/block-library/src/query-title/block.json index a5298bc89c2a..0dd85c2425b5 100644 --- a/packages/block-library/src/query-title/block.json +++ b/packages/block-library/src/query-title/block.json @@ -3,7 +3,7 @@ "apiVersion": 2, "name": "core/query-title", "title": "Query Title", - "category": "design", + "category": "theme", "description": "Display the query title.", "textdomain": "default", "attributes": { diff --git a/packages/block-library/src/site-logo/block.json b/packages/block-library/src/site-logo/block.json index 33e4f415c17a..798917ff7cb8 100644 --- a/packages/block-library/src/site-logo/block.json +++ b/packages/block-library/src/site-logo/block.json @@ -3,7 +3,7 @@ "apiVersion": 2, "name": "core/site-logo", "title": "Site Logo", - "category": "layout", + "category": "theme", "description": "Display a graphic to represent this site. Update the block, and the changes apply everywhere it’s used. This is different than the site icon, which is the smaller image visible in your dashboard, browser tabs, etc used to help others recognize this site.", "textdomain": "default", "attributes": { diff --git a/packages/block-library/src/site-tagline/block.json b/packages/block-library/src/site-tagline/block.json index c9e00d104785..451a777ee9de 100644 --- a/packages/block-library/src/site-tagline/block.json +++ b/packages/block-library/src/site-tagline/block.json @@ -3,7 +3,7 @@ "apiVersion": 2, "name": "core/site-tagline", "title": "Site Tagline", - "category": "design", + "category": "theme", "description": "Describe in a few words what the site is about. The tagline can be used in search results or when sharing on social networks even if it's not displayed in the theme design.", "keywords": [ "description" ], "textdomain": "default", diff --git a/packages/block-library/src/site-title/block.json b/packages/block-library/src/site-title/block.json index efd951b0e09c..1408067751ee 100644 --- a/packages/block-library/src/site-title/block.json +++ b/packages/block-library/src/site-title/block.json @@ -3,7 +3,7 @@ "apiVersion": 2, "name": "core/site-title", "title": "Site Title", - "category": "design", + "category": "theme", "description": "Displays the name of this site. Update the block, and the changes apply everywhere it’s used. This will also appear in the browser title bar and in search results.", "textdomain": "default", "attributes": {