From ebdd26756ddcf44d10ff0c67a0c819e944a7c06b Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Mon, 5 Sep 2022 12:53:44 +0300 Subject: [PATCH] Lodash: Refactor away from BlockActions --- .../src/components/block-actions/index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/block-actions/index.js b/packages/block-editor/src/components/block-actions/index.js index 704a3f4ad00f1..f94f16e925628 100644 --- a/packages/block-editor/src/components/block-actions/index.js +++ b/packages/block-editor/src/components/block-actions/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { castArray, first, last, every } from 'lodash'; - /** * WordPress dependencies */ @@ -36,7 +31,7 @@ export default function BlockActions( { const blocks = getBlocksByClientId( clientIds ); const rootClientId = getBlockRootClientId( clientIds[ 0 ] ); - const canDuplicate = every( blocks, ( block ) => { + const canDuplicate = blocks.every( ( block ) => { return ( !! block && hasBlockSupport( block.name, 'multiple', true ) && @@ -80,10 +75,16 @@ export default function BlockActions( { return removeBlocks( clientIds, updateSelection ); }, onInsertBefore() { - insertBeforeBlock( first( castArray( clientIds ) ) ); + const clientId = Array.isArray( clientIds ) + ? clientIds[ 0 ] + : clientId; + insertBeforeBlock( clientId ); }, onInsertAfter() { - insertAfterBlock( last( castArray( clientIds ) ) ); + const clientId = Array.isArray( clientIds ) + ? clientIds[ clientIds.length - 1 ] + : clientId; + insertAfterBlock( clientId ); }, onMoveTo() { setNavigationMode( true );