woocommerce/packages/woocommerce-blocks/assets/js/atomic/utils/create-blocks-from-template.js
2021-12-10 12:03:04 +00:00

19 lines
464 B
JavaScript

/**
* External dependencies
*/
import { createBlock } from '@wordpress/blocks';
/**
* Creates blocks for a given inner blocks Template.
*
* @param {Array} template Inner Blocks Template.
*/
export const createBlocksFromTemplate = ( template ) => {
return template.map( ( [ name, atts = {}, innerBlocks = [] ] ) => {
const children = innerBlocks
? createBlocksFromTemplate( innerBlocks )
: [];
return createBlock( name, atts, children );
} );
};