diff --git a/wp-modules/editor/js/src/components/PatternEdit/index.tsx b/wp-modules/editor/js/src/blocks/pattern-block/PatternEdit.tsx similarity index 100% rename from wp-modules/editor/js/src/components/PatternEdit/index.tsx rename to wp-modules/editor/js/src/blocks/pattern-block/PatternEdit.tsx diff --git a/wp-modules/editor/js/src/utils/registerPatternBlock.ts b/wp-modules/editor/js/src/blocks/pattern-block/registerPatternBlock.ts similarity index 92% rename from wp-modules/editor/js/src/utils/registerPatternBlock.ts rename to wp-modules/editor/js/src/blocks/pattern-block/registerPatternBlock.ts index 9ea391e5..6e25a220 100644 --- a/wp-modules/editor/js/src/utils/registerPatternBlock.ts +++ b/wp-modules/editor/js/src/blocks/pattern-block/registerPatternBlock.ts @@ -1,5 +1,5 @@ import { __ } from '@wordpress/i18n'; -import PatternEdit from '../components/PatternEdit'; +import PatternEdit from './PatternEdit'; export default function registerPatternBlock( settings: Record< string, unknown >, diff --git a/wp-modules/editor/js/src/components/PatternEdit/index.test.tsx b/wp-modules/editor/js/src/blocks/pattern-block/test/PatternEdit.tsx similarity index 86% rename from wp-modules/editor/js/src/components/PatternEdit/index.test.tsx rename to wp-modules/editor/js/src/blocks/pattern-block/test/PatternEdit.tsx index f69f4221..237af9ef 100644 --- a/wp-modules/editor/js/src/components/PatternEdit/index.test.tsx +++ b/wp-modules/editor/js/src/blocks/pattern-block/test/PatternEdit.tsx @@ -1,7 +1,7 @@ import { render } from '@testing-library/react'; -import PatternEdit from './'; +import PatternEdit from '../PatternEdit'; -jest.mock( '../../globals', () => { +jest.mock( '../../../globals', () => { return { patternManager: { patterns: { @@ -18,11 +18,11 @@ jest.mock( '../../globals', () => { }; } ); -jest.mock( '../../hooks/useSavedPostData', () => { +jest.mock( '../../../hooks/useSavedPostData', () => { return () => ( {} ); } ); -jest.mock( '../../../../../app/js/src/components/PatternPreview', () => { +jest.mock( '../../../../../../app/js/src/components/PatternPreview', () => { return () => null; } ); diff --git a/wp-modules/editor/js/src/utils/test/registerPatternBlock.ts b/wp-modules/editor/js/src/blocks/pattern-block/test/registerPatternBlock.ts similarity index 100% rename from wp-modules/editor/js/src/utils/test/registerPatternBlock.ts rename to wp-modules/editor/js/src/blocks/pattern-block/test/registerPatternBlock.ts diff --git a/wp-modules/editor/js/src/index.ts b/wp-modules/editor/js/src/index.ts index 99d94b38..4361eadb 100644 --- a/wp-modules/editor/js/src/index.ts +++ b/wp-modules/editor/js/src/index.ts @@ -7,7 +7,7 @@ import PatternManagerMetaControls from './components/PatternManagerMetaControls' import changeWords from './utils/changeWords'; import preventTransform from './utils/preventTransform'; import receiveActiveTheme from './utils/receiveActiveTheme'; -import registerPatternBlock from './utils/registerPatternBlock'; +import registerPatternBlock from './blocks/pattern-block/registerPatternBlock'; registerPlugin( 'pattern-manager-postmeta-for-patterns', { icon: null, diff --git a/wp-modules/editor/js/src/utils/filterOutPatterns.ts b/wp-modules/editor/js/src/utils/filterOutPatterns.ts index cac14c3e..2be8f80a 100644 --- a/wp-modules/editor/js/src/utils/filterOutPatterns.ts +++ b/wp-modules/editor/js/src/utils/filterOutPatterns.ts @@ -1,5 +1,5 @@ import { parse } from '@wordpress/blocks'; -import hasPmPatternBlock from './hasPmPatternBlock'; +import hasBlock from './hasBlock'; import type { Pattern, Patterns } from '../types'; /** @@ -14,7 +14,8 @@ export default function filterOutPatterns( ( accumulator, [ key, pattern ] ) => { return { ...accumulator, - ...( ! hasPmPatternBlock( + ...( ! hasBlock( + 'core/pattern', parse( pattern.content ), patternName ) && pattern.name !== patternName diff --git a/wp-modules/editor/js/src/utils/hasPmPatternBlock.ts b/wp-modules/editor/js/src/utils/hasBlock.ts similarity index 58% rename from wp-modules/editor/js/src/utils/hasPmPatternBlock.ts rename to wp-modules/editor/js/src/utils/hasBlock.ts index 732f6d99..632ba09f 100644 --- a/wp-modules/editor/js/src/utils/hasPmPatternBlock.ts +++ b/wp-modules/editor/js/src/utils/hasBlock.ts @@ -1,14 +1,15 @@ import type { Block, Pattern } from '../types'; -export default function hasPmPatternBlock( +export default function hasBlock( + blockName: String, blocks: Block[], patternName: Pattern[ 'name' ] ) { return blocks.some( ( block ) => { return ( - ( block.name === 'core/pattern' && + ( block.name === blockName && block.attributes?.slug === patternName ) || - hasPmPatternBlock( block?.innerBlocks ?? [], patternName ) + hasBlock( blockName, block?.innerBlocks ?? [], patternName ) ); } ); } diff --git a/wp-modules/editor/js/src/utils/test/hasPmPatternBlock.ts b/wp-modules/editor/js/src/utils/test/hasBlock.ts similarity index 89% rename from wp-modules/editor/js/src/utils/test/hasPmPatternBlock.ts rename to wp-modules/editor/js/src/utils/test/hasBlock.ts index 707ed36f..7c4acfc1 100644 --- a/wp-modules/editor/js/src/utils/test/hasPmPatternBlock.ts +++ b/wp-modules/editor/js/src/utils/test/hasBlock.ts @@ -1,6 +1,6 @@ -import hasPmPatternBlock from '../hasPmPatternBlock'; +import hasBlock from '../hasBlock'; -describe( 'hasPmPatternBlock', () => { +describe( 'hasBlock', () => { it.each( [ [ [ { name: '', attributes: {} } ], '', false ], [ [ { name: '', attributes: {} } ], 'example-slug', false ], @@ -75,7 +75,7 @@ describe( 'hasPmPatternBlock', () => { ] )( 'should get whether there is a Pattern Block', ( blocks, patternSlug, expected ) => { - expect( hasPmPatternBlock( blocks, patternSlug ) ).toEqual( + expect( hasBlock( 'core/pattern', blocks, patternSlug ) ).toEqual( expected ); }