2023-10-02 08:28:13 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { BlockInstance } from '@wordpress/blocks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2024-05-28 07:32:26 +00:00
|
|
|
import { PatternWithBlocks } from '~/customize-store/types/pattern';
|
2023-10-02 08:28:13 +00:00
|
|
|
|
|
|
|
export const findPatternByBlock = (
|
|
|
|
patterns: PatternWithBlocks[],
|
|
|
|
block: BlockInstance
|
|
|
|
) => {
|
|
|
|
const blockAttributes = block.attributes;
|
|
|
|
if (
|
|
|
|
blockAttributes.className &&
|
|
|
|
blockAttributes.className.includes( 'preview-opacity' )
|
|
|
|
) {
|
|
|
|
// Remove the preview opacity class from the footer block because it's added by the editor, not the pattern.
|
|
|
|
blockAttributes.className = blockAttributes.className.replaceAll(
|
|
|
|
' preview-opacity',
|
|
|
|
''
|
|
|
|
);
|
|
|
|
}
|
2024-07-23 08:59:08 +00:00
|
|
|
|
2024-03-05 17:21:44 +00:00
|
|
|
return patterns.find( ( pattern ) => {
|
|
|
|
const patternBlocks = pattern.blocks[ 0 ];
|
2023-10-02 08:28:13 +00:00
|
|
|
|
2024-07-23 08:59:08 +00:00
|
|
|
return (
|
|
|
|
patternBlocks.attributes.className === block.attributes.className
|
|
|
|
);
|
2024-03-05 17:21:44 +00:00
|
|
|
} );
|
2023-10-02 08:28:13 +00:00
|
|
|
};
|