Skip to content

Commit

Permalink
use to transforms for patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Mar 26, 2021
1 parent 3814f5b commit 21e8e75
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { __ } from '@wordpress/i18n';
import { useState, useMemo } from '@wordpress/element';
import { useInstanceId } from '@wordpress/compose';
import { chevronRight } from '@wordpress/icons';
import { cloneBlock, getBlockType } from '@wordpress/blocks';
import { cloneBlock, getBlockTransforms } from '@wordpress/blocks';
import {
MenuGroup,
MenuItem,
Expand Down Expand Up @@ -110,9 +110,11 @@ function PatternTransformationsMenu( {
// everything else from the pattern's block.
// If `retainAttributes` are not set, update the match
// with all the selected block's attributes.
const blockType = getBlockType( block.name );
const retainAttributes =
blockType.transforms?.retainAttributes;
const retainAttributes = getBlockTransforms(
'to',
block.name
).find( ( { type } ) => type === 'pattern' )
?.retainAttributes;
let retainedBlockAttributes = block.attributes;
if ( retainAttributes?.length ) {
retainedBlockAttributes = retainAttributes.reduce(
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/heading/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { getLevelFromHeadingNodeName } from './shared';
import { name } from './block.json';

const transforms = {
retainAttributes: [ 'content' ],
from: [
{
type: 'block',
Expand Down Expand Up @@ -92,6 +91,7 @@ const transforms = {
} )
),
},
{ type: 'pattern', retainAttributes: [ 'content' ] },
],
};

Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/paragraph/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { createBlock, getBlockAttributes } from '@wordpress/blocks';
import { name } from './block.json';

const transforms = {
retainAttributes: [ 'content' ],
from: [
{
type: 'raw',
Expand Down Expand Up @@ -38,6 +37,7 @@ const transforms = {
},
},
],
to: [ { type: 'pattern', retainAttributes: [ 'content' ] } ],
};

export default transforms;

0 comments on commit 21e8e75

Please sign in to comment.