diff --git a/packages/blocks/src/api/factory.js b/packages/blocks/src/api/factory.js index 6df8eb00005a8e..2842c68de1c813 100644 --- a/packages/blocks/src/api/factory.js +++ b/packages/blocks/src/api/factory.js @@ -83,37 +83,33 @@ export function createBlocksFromInnerBlocksTemplate( * Given a block object, returns a copy of the block object while sanitizing its attributes, * optionally merging new attributes and/or replacing its inner blocks. * - * @param {Object} block Block instance. - * @param {Object} mergeAttributes Block attributes. - * @param {?Array} newInnerBlocks Nested blocks. + * @param {Object} block Block instance. * * @return {Object} A cloned block. */ -export function __experimentalCloneSanitizedBlock( - block, - mergeAttributes = {}, - newInnerBlocks -) { +export function __experimentalCloneSanitizedBlock( block ) { const clientId = uuid(); const sanitizedAttributes = __experimentalSanitizeBlockAttributes( block.name, - { - ...block.attributes, - ...mergeAttributes, - } + block.attributes ); - return { + let newBlock = { ...block, clientId, attributes: sanitizedAttributes, - innerBlocks: - newInnerBlocks || - block.innerBlocks.map( ( innerBlock ) => - __experimentalCloneSanitizedBlock( innerBlock ) - ), + innerBlocks: block.innerBlocks.map( ( innerBlock ) => + __experimentalCloneSanitizedBlock( innerBlock ) + ), }; + + const blockType = getBlockType( block.name ); + if ( blockType?.copy ) { + newBlock = blockType.copy( newBlock ); + } + + return newBlock; } /**