Skip to content

Commit

Permalink
[Inserter]: Adjust order of theme blocks and reorder inserter items (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ntsekouras committed Nov 26, 2021
1 parent c9e32e0 commit e63294c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 56 deletions.
40 changes: 14 additions & 26 deletions packages/block-editor/src/store/selectors.js
Expand Up @@ -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),
Expand All @@ -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 ) => [
Expand Down
52 changes: 27 additions & 25 deletions packages/block-library/src/index.js
Expand Up @@ -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,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/post-terms/block.json
Expand Up @@ -3,7 +3,7 @@
"apiVersion": 2,
"name": "core/post-terms",
"title": "Post Terms",
"category": "design",
"category": "theme",
"description": "Post terms.",
"textdomain": "default",
"attributes": {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/query-title/block.json
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/site-logo/block.json
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/site-tagline/block.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/site-title/block.json
Expand Up @@ -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": {
Expand Down

0 comments on commit e63294c

Please sign in to comment.