diff --git a/apps/wpcom-block-editor/README.md b/apps/wpcom-block-editor/README.md index d01024f33f722..3b502ea958351 100644 --- a/apps/wpcom-block-editor/README.md +++ b/apps/wpcom-block-editor/README.md @@ -21,6 +21,9 @@ There are two environments the block editor integration supports: - `disable-nux-tour.js`: Disable the pop-up tooltip tour that is displayed on first use. - `rich-text.js`: Extensions for the Rich Text toolbar with the Calypso buttons missing on Core (i.e. underline, justify). - `switch-to-classic.js`: Append a button to the "More tools" menu for switching to the classic editor. +- `tracking`: Adds analytics around specific user actions for Simple, Jetpack and Atomic sites. +- `reorder-block-categories`: Moves Jetpack and CoBlocks Block Categories below Core Categories +- `unregister-experimental-blocks`: Removes some experimental blocks from the Gutenberg Plugin. ### Calypso utilities diff --git a/apps/wpcom-block-editor/src/common/index.js b/apps/wpcom-block-editor/src/common/index.js index 0fc8c9239fda8..676e3bb6b07aa 100644 --- a/apps/wpcom-block-editor/src/common/index.js +++ b/apps/wpcom-block-editor/src/common/index.js @@ -2,8 +2,9 @@ * Internal dependencies */ import './disable-nux-tour'; +import './reorder-block-categories'; import './rich-text'; -import './switch-to-classic'; import './style.scss'; -import './unregister-experimental-blocks'; +import './switch-to-classic'; import './tracking'; +import './unregister-experimental-blocks'; diff --git a/apps/wpcom-block-editor/src/common/reorder-block-categories.js b/apps/wpcom-block-editor/src/common/reorder-block-categories.js new file mode 100644 index 0000000000000..ab50dde729a64 --- /dev/null +++ b/apps/wpcom-block-editor/src/common/reorder-block-categories.js @@ -0,0 +1,47 @@ +/* eslint-disable import/no-extraneous-dependencies */ +/** + * External dependencies + */ +import { getCategories, setCategories } from '@wordpress/blocks'; +import domReady from '@wordpress/dom-ready'; + +const categorySlugs = [ 'jetpack', 'coblocks', 'coblocks-galleries' ]; + +// Very fragile checks, we'll replace with proper common bundle splitting in https://github.com/Automattic/wp-calypso/issues/34476 +const isSimpleSite = !! window.wpcomGutenberg.pluginVersion; +const isAtomicSite = window._currentSiteType === 'atomic'; + +if ( isAtomicSite || isSimpleSite ) { + domReady( function() { + //preserve order of other columns, and split matching + const { core: coreCategories, custom: unsorted } = getCategories().reduce( + ( { core, custom }, category ) => { + const isCustomCategory = categorySlugs.includes( category.slug ); + if ( isCustomCategory ) { + return { + core, + custom: [ ...custom, category ], + }; + } + return { + core: [ ...core, category ], + custom, + }; + }, + { custom: [], core: [] } + ); + //sort once following order of categorySlugs + const customCategories = unsorted.sort( ( { slug }, { slug: slugB } ) => { + const index = categorySlugs.indexOf( slug ); + const indexB = categorySlugs.indexOf( slugB ); + if ( index === indexB ) { + return 0; + } + if ( index < indexB ) { + return -1; + } + return 1; + } ); + setCategories( [ ...coreCategories, ...customCategories ] ); + } ); +}