Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Inserter]: Adjust order of theme blocks and reorder inserter items #36719

Merged
merged 6 commits into from Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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