diff --git a/packages/block-editor/src/components/block-mover/button.js b/packages/block-editor/src/components/block-mover/button.js index 6713d5d273d86..2b820a481b583 100644 --- a/packages/block-editor/src/components/block-mover/button.js +++ b/packages/block-editor/src/components/block-mover/button.js @@ -2,7 +2,6 @@ * External dependencies */ import classnames from 'classnames'; -import { castArray, first, last } from 'lodash'; /** * WordPress dependencies @@ -62,7 +61,10 @@ const BlockMoverButton = forwardRef( ref ) => { const instanceId = useInstanceId( BlockMoverButton ); - const blocksCount = castArray( clientIds ).length; + const normalizedClientIds = Array.isArray( clientIds ) + ? clientIds + : [ clientIds ]; + const blocksCount = normalizedClientIds.length; const { blockType, @@ -81,12 +83,11 @@ const BlockMoverButton = forwardRef( getBlock, getBlockListSettings, } = select( blockEditorStore ); - const normalizedClientIds = castArray( clientIds ); - const firstClientId = first( normalizedClientIds ); + const firstClientId = normalizedClientIds[ 0 ]; const blockRootClientId = getBlockRootClientId( firstClientId ); const firstBlockIndex = getBlockIndex( firstClientId ); const lastBlockIndex = getBlockIndex( - last( normalizedClientIds ) + normalizedClientIds[ normalizedClientIds.length - 1 ] ); const blockOrder = getBlockOrder( blockRootClientId ); const block = getBlock( firstClientId ); diff --git a/packages/block-editor/src/components/block-mover/index.js b/packages/block-editor/src/components/block-mover/index.js index 9087cada5c02a..9b9f32457561e 100644 --- a/packages/block-editor/src/components/block-mover/index.js +++ b/packages/block-editor/src/components/block-mover/index.js @@ -1,7 +1,6 @@ /** * External dependencies */ -import { first, last, castArray } from 'lodash'; import classnames from 'classnames'; /** @@ -30,13 +29,15 @@ function BlockMover( { clientIds, hideDragHandle } ) { getBlockOrder, getBlockRootClientId, } = select( blockEditorStore ); - const normalizedClientIds = castArray( clientIds ); - const firstClientId = first( normalizedClientIds ); - const _rootClientId = getBlockRootClientId( - first( normalizedClientIds ) - ); + const normalizedClientIds = Array.isArray( clientIds ) + ? clientIds + : [ clientIds ]; + const firstClientId = normalizedClientIds[ 0 ]; + const _rootClientId = getBlockRootClientId( firstClientId ); const firstIndex = getBlockIndex( firstClientId ); - const lastIndex = getBlockIndex( last( normalizedClientIds ) ); + const lastIndex = getBlockIndex( + normalizedClientIds[ normalizedClientIds.length - 1 ] + ); const blockOrder = getBlockOrder( _rootClientId ); return { diff --git a/packages/block-editor/src/components/block-mover/index.native.js b/packages/block-editor/src/components/block-mover/index.native.js index 0734b304cdbf6..852515a343821 100644 --- a/packages/block-editor/src/components/block-mover/index.native.js +++ b/packages/block-editor/src/components/block-mover/index.native.js @@ -1,7 +1,6 @@ /** * External dependencies */ -import { first, last, partial, castArray } from 'lodash'; import { Platform } from 'react-native'; /** @@ -149,12 +148,16 @@ export default compose( getBlockRootClientId, getBlockOrder, } = select( blockEditorStore ); - const normalizedClientIds = castArray( clientIds ); - const firstClientId = first( normalizedClientIds ); + const normalizedClientIds = Array.isArray( clientIds ) + ? clientIds + : [ clientIds ]; + const firstClientId = normalizedClientIds[ 0 ]; const rootClientId = getBlockRootClientId( firstClientId ); const blockOrder = getBlockOrder( rootClientId ); const firstIndex = getBlockIndex( firstClientId ); - const lastIndex = getBlockIndex( last( normalizedClientIds ) ); + const lastIndex = getBlockIndex( + normalizedClientIds[ normalizedClientIds.length - 1 ] + ); return { firstIndex, @@ -169,15 +172,19 @@ export default compose( const { moveBlocksDown, moveBlocksUp, moveBlocksToPosition } = dispatch( blockEditorStore ); return { - onMoveDown: partial( moveBlocksDown, clientIds, rootClientId ), - onMoveUp: partial( moveBlocksUp, clientIds, rootClientId ), - onLongMove: ( targetIndex ) => - partial( - moveBlocksToPosition, - clientIds, - rootClientId, - targetIndex - ), + onMoveDown: ( ...args ) => + moveBlocksDown( clientIds, rootClientId, ...args ), + onMoveUp: ( ...args ) => + moveBlocksUp( clientIds, rootClientId, ...args ), + onLongMove: + ( targetIndex ) => + ( ...args ) => + moveBlocksToPosition( + clientIds, + rootClientId, + targetIndex, + ...args + ), }; } ), withInstanceId