From 4df8100b10306f51504bf6985ad9ba97ca42688d Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 30 Mar 2023 16:21:34 +1100 Subject: [PATCH] Add a copy filter that lets plugins customise how they are duplicated --- packages/blocks/src/api/factory.js | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/blocks/src/api/factory.js b/packages/blocks/src/api/factory.js index 6df8eb00005a8e..ad96b7f0136be7 100644 --- a/packages/blocks/src/api/factory.js +++ b/packages/blocks/src/api/factory.js @@ -83,37 +83,28 @@ 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 { + const newBlock = { ...block, clientId, attributes: sanitizedAttributes, - innerBlocks: - newInnerBlocks || - block.innerBlocks.map( ( innerBlock ) => - __experimentalCloneSanitizedBlock( innerBlock ) - ), + innerBlocks: block.innerBlocks.map( ( innerBlock ) => + __experimentalCloneSanitizedBlock( innerBlock ) + ), }; + + return applyFilters( 'blocks.copyBlock', newBlock ); } /**