From 32a7053db931c5bddecae9b22795d02d91f8d744 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 25 Nov 2021 16:08:19 +0200 Subject: [PATCH] reorder blocks and make variations appear right after their source block --- packages/block-editor/src/store/selectors.js | 40 +++++++------------- packages/block-library/src/index.js | 4 +- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 0aec0c6791139..68e06da5d3e38 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 a2476fc0de97c..cf39eb89741dd 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -149,6 +149,8 @@ export const __experimentalGetCoreBlocks = () => [ html, latestComments, latestPosts, + templatePart, + query, logInOut, mediaText, missing, @@ -171,7 +173,6 @@ export const __experimentalGetCoreBlocks = () => [ postTitle, preformatted, pullquote, - query, queryPagination, queryPaginationNext, queryPaginationNumbers, @@ -191,7 +192,6 @@ export const __experimentalGetCoreBlocks = () => [ table, // tableOfContents, tagCloud, - templatePart, termDescription, textColumns, verse,