2022-11-09 01:53:26 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { selectBlockByName } from '.';
|
2022-11-16 01:52:51 +00:00
|
|
|
import { insertBlockUsingQuickInserter } from './insert-block-using-quick-inserter';
|
2022-11-09 01:53:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts an inner block into the currently selected block. If a parent block
|
|
|
|
* is provided, it will be selected before inserting the inner block.
|
|
|
|
*
|
|
|
|
* We make the parentBlockName optional to add more flexibility to the function,
|
|
|
|
* enabling tests to have more control over the selection of the parent block.
|
|
|
|
*
|
2023-12-12 23:05:20 +00:00
|
|
|
* @param blockTitle Block title, such as "Add to Cart Button".
|
|
|
|
* @param parentBlockName Parent block name, such as core/group.
|
2022-11-09 01:53:26 +00:00
|
|
|
*/
|
|
|
|
export const insertInnerBlock = async (
|
|
|
|
blockTitle: string,
|
|
|
|
parentBlockName = ''
|
|
|
|
) => {
|
|
|
|
if ( parentBlockName ) {
|
|
|
|
await selectBlockByName( parentBlockName );
|
|
|
|
}
|
2022-11-16 01:52:51 +00:00
|
|
|
|
|
|
|
await insertBlockUsingQuickInserter( blockTitle );
|
2022-11-09 01:53:26 +00:00
|
|
|
};
|