Skip to content

Commit

Permalink
Remove need for 'block-editor-block-list-block__wrapper'.
Browse files Browse the repository at this point in the history
This makes it possible to switch to a callback-based API, e.g. "itemWrapper={ ( item ) => <div>{ item }</div> }".
  • Loading branch information
ZebulanStanphill committed Aug 5, 2020
1 parent 03d17b1 commit 87f98c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
6 changes: 1 addition & 5 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,7 @@ function BlockListBlock( {
}

if ( Wrapper ) {
blockEdit = (
<Wrapper className="block-editor-block-list-block__wrapper">
{ blockEdit }
</Wrapper>
);
blockEdit = <Wrapper>{ blockEdit }</Wrapper>;
}

const value = {
Expand Down
27 changes: 15 additions & 12 deletions packages/block-editor/src/components/use-block-drop-zone/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { difference } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -50,17 +55,6 @@ export function getNearestBlockIndex( elements, position, orientation ) {
let candidateDistance;

elements.forEach( ( element, index ) => {
// Ensure the element is a block (has the `wp-block` class) or is an
// InnerBlocks item wrapper.
if (
! element.classList.contains( 'wp-block' ) &&
! element.classList.contains(
'block-editor-block-list-block__wrapper'
)
) {
return;
}

const rect = element.getBoundingClientRect();
const cursorLateralPosition = isHorizontal ? y : x;
const cursorForwardPosition = isHorizontal ? x : y;
Expand Down Expand Up @@ -332,7 +326,16 @@ export default function useBlockDropZone( {

useEffect( () => {
if ( position ) {
const blockElements = Array.from( element.current.children );
// Get the root elements of blocks inside the element, ignoring
// InnerBlocks item wrappers and the children of the blocks.
const blockElements = difference(
Array.from( element.current.querySelectorAll( '.wp-block' ) ),
Array.from(
element.current.querySelectorAll(
':scope .wp-block .wp-block'
)
)
);

const targetIndex = getNearestBlockIndex(
blockElements,
Expand Down

0 comments on commit 87f98c3

Please sign in to comment.