From 21e8e75a24abe1e20a79010c8e4a1d2533c68dc3 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Wed, 24 Mar 2021 12:03:16 +0200 Subject: [PATCH] use `to` transforms for patterns --- .../block-switcher/pattern-transformations-menu.js | 10 ++++++---- packages/block-library/src/heading/transforms.js | 2 +- packages/block-library/src/paragraph/transforms.js | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/block-editor/src/components/block-switcher/pattern-transformations-menu.js b/packages/block-editor/src/components/block-switcher/pattern-transformations-menu.js index 1bea3740d79ee..f2579cc69f3cc 100644 --- a/packages/block-editor/src/components/block-switcher/pattern-transformations-menu.js +++ b/packages/block-editor/src/components/block-switcher/pattern-transformations-menu.js @@ -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, @@ -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( diff --git a/packages/block-library/src/heading/transforms.js b/packages/block-library/src/heading/transforms.js index ef0e1dddbce83..17fcb2719e605 100644 --- a/packages/block-library/src/heading/transforms.js +++ b/packages/block-library/src/heading/transforms.js @@ -10,7 +10,6 @@ import { getLevelFromHeadingNodeName } from './shared'; import { name } from './block.json'; const transforms = { - retainAttributes: [ 'content' ], from: [ { type: 'block', @@ -92,6 +91,7 @@ const transforms = { } ) ), }, + { type: 'pattern', retainAttributes: [ 'content' ] }, ], }; diff --git a/packages/block-library/src/paragraph/transforms.js b/packages/block-library/src/paragraph/transforms.js index 3ee12658bda9c..e59b01ad14e3b 100644 --- a/packages/block-library/src/paragraph/transforms.js +++ b/packages/block-library/src/paragraph/transforms.js @@ -9,7 +9,6 @@ import { createBlock, getBlockAttributes } from '@wordpress/blocks'; import { name } from './block.json'; const transforms = { - retainAttributes: [ 'content' ], from: [ { type: 'raw', @@ -38,6 +37,7 @@ const transforms = { }, }, ], + to: [ { type: 'pattern', retainAttributes: [ 'content' ] } ], }; export default transforms;