From 7a9ebe62887dac0bf8ed41496b28e64b46bacfe6 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 1 Aug 2023 16:50:11 +1200 Subject: [PATCH 1/2] Show the default patterns icons for all pattern blocks in inserter --- packages/block-editor/src/store/selectors.js | 45 +------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index e459e536c90914..1c9a2c1348ce0c 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1962,51 +1962,8 @@ const buildBlockTypeItem = */ export const getInserterItems = createSelector( ( state, rootClientId = null ) => { - /* - * Matches block comment delimiters amid serialized content. - * - * @see `tokenizer` in `@wordpress/block-serialization-default-parser` - * package - * - * blockParserTokenizer differs from the original tokenizer in the - * following ways: - * - * - removed global flag (/g) - * - prepended ^\s* - * - */ - const blockParserTokenizer = - /^\s*)[^])*)\5|[^]*?)}\s+)?(\/)?-->/; - const buildReusableBlockInserterItem = ( reusableBlock ) => { - let icon = symbol; - - /* - * Instead of always displaying a generic "symbol" icon for every - * reusable block, try to use an icon that represents the first - * outermost block contained in the reusable block. This requires - * scanning the serialized form of the reusable block to find its - * first block delimiter, then looking up the corresponding block - * type, if available. - */ - if ( Platform.OS === 'web' ) { - const content = - typeof reusableBlock.content.raw === 'string' - ? reusableBlock.content.raw - : reusableBlock.content; - const rawBlockMatch = content.match( blockParserTokenizer ); - if ( rawBlockMatch ) { - const [ , , namespace = 'core/', blockName ] = - rawBlockMatch; - const referencedBlockType = getBlockType( - namespace + blockName - ); - if ( referencedBlockType ) { - icon = referencedBlockType.icon; - } - } - } - + const icon = symbol; const id = `core/block/${ reusableBlock.id }`; const { time, count = 0 } = getInsertUsage( state, id ) || {}; const frecency = calculateFrecency( time, count ); From b5ce419d08ca72a00519c77e6cd1e456d9e4c66b Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 2 Aug 2023 09:48:42 +1200 Subject: [PATCH 2/2] Fix unit test --- packages/block-editor/src/store/test/selectors.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index 9140248391cf8e..fd10f9189a4ef3 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -7,6 +7,7 @@ import { setFreeformContentHandlerName, } from '@wordpress/blocks'; import { RawHTML } from '@wordpress/element'; +import { symbol } from '@wordpress/icons'; /** * Internal dependencies @@ -3347,7 +3348,7 @@ describe( 'selectors', () => { category: 'reusable', content: '', frecency: 0, - icon: { src: 'test' }, + icon: symbol, id: 'core/block/1', initialAttributes: { ref: 1 }, isDisabled: false,