Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #170 from studiopress/try/move-blocks-to-their-own…
Browse files Browse the repository at this point in the history
…-files

Try moving blocks to their own modular directories
  • Loading branch information
johnstonphilip authored May 16, 2023
2 parents 3cbc07a + 4de5cae commit 141fff9
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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 >,
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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;
} );

Expand Down
2 changes: 1 addition & 1 deletion wp-modules/editor/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions wp-modules/editor/js/src/utils/filterOutPatterns.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from '@wordpress/blocks';
import hasPmPatternBlock from './hasPmPatternBlock';
import hasBlock from './hasBlock';
import type { Pattern, Patterns } from '../types';

/**
Expand All @@ -14,7 +14,8 @@ export default function filterOutPatterns(
( accumulator, [ key, pattern ] ) => {
return {
...accumulator,
...( ! hasPmPatternBlock(
...( ! hasBlock(
'core/pattern',
parse( pattern.content ),
patternName
) && pattern.name !== patternName
Expand Down
Original file line number Diff line number Diff line change
@@ -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 )
);
} );
}
Original file line number Diff line number Diff line change
@@ -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 ],
Expand Down Expand Up @@ -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
);
}
Expand Down

0 comments on commit 141fff9

Please sign in to comment.