From be391a9c1151b2dc4ecc3a23db20f014806d95ab Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 17 Jun 2021 19:38:14 +0800 Subject: [PATCH 1/3] Check for style elements --- .../src/components/use-block-drop-zone/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/use-block-drop-zone/index.js b/packages/block-editor/src/components/use-block-drop-zone/index.js index 62e13c9b6b0af9..f5c810b12edc48 100644 --- a/packages/block-editor/src/components/use-block-drop-zone/index.js +++ b/packages/block-editor/src/components/use-block-drop-zone/index.js @@ -105,7 +105,11 @@ export default function useBlockDropZone( { const onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex ); const throttled = useThrottle( useCallback( ( event, currentTarget ) => { - const blockElements = Array.from( currentTarget.children ); + const blockElements = Array.from( currentTarget.children ).filter( + ( element ) => { + return element.nodeName !== 'STYLE'; + } + ); const targetIndex = getNearestBlockIndex( blockElements, { x: event.clientX, y: event.clientY }, From e45fbcbb6633fc9c75feb2a72ee7048fea28019a Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 17 Jun 2021 19:46:22 +0800 Subject: [PATCH 2/3] Use wp-block classname --- .../src/components/use-block-drop-zone/index.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/use-block-drop-zone/index.js b/packages/block-editor/src/components/use-block-drop-zone/index.js index f5c810b12edc48..a034f1af2d7e7b 100644 --- a/packages/block-editor/src/components/use-block-drop-zone/index.js +++ b/packages/block-editor/src/components/use-block-drop-zone/index.js @@ -43,11 +43,6 @@ export function getNearestBlockIndex( elements, position, orientation ) { let candidateDistance; elements.forEach( ( element, index ) => { - // Ensure the element is a block. It should have the `wp-block` class. - if ( ! element.classList.contains( 'wp-block' ) ) { - return; - } - const rect = element.getBoundingClientRect(); const [ distance, edge ] = getDistanceToNearestEdge( position, @@ -106,9 +101,8 @@ export default function useBlockDropZone( { const throttled = useThrottle( useCallback( ( event, currentTarget ) => { const blockElements = Array.from( currentTarget.children ).filter( - ( element ) => { - return element.nodeName !== 'STYLE'; - } + // Ensure the element is a block. It should have the `wp-block` class. + ( element ) => element.classList.contains( 'wp-block' ) ); const targetIndex = getNearestBlockIndex( blockElements, From c31a9baa0cb8f54117e1f3205143ac09c66144be Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 22 Jun 2021 12:51:31 +0800 Subject: [PATCH 3/3] Remove test that is no longer valid --- .../components/use-block-drop-zone/test/index.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/packages/block-editor/src/components/use-block-drop-zone/test/index.js b/packages/block-editor/src/components/use-block-drop-zone/test/index.js index 42a9476be0cd41..d60ee4ba574b50 100644 --- a/packages/block-editor/src/components/use-block-drop-zone/test/index.js +++ b/packages/block-editor/src/components/use-block-drop-zone/test/index.js @@ -83,22 +83,6 @@ describe( 'getNearestBlockIndex', () => { expect( result ).toBeUndefined(); } ); - it( 'returns `undefined` if the elements do not have the `wp-block` class', () => { - const nonBlockElements = [ - { classList: createMockClassList( 'some-other-class' ) }, - ]; - const position = { x: 0, y: 0 }; - const orientation = 'horizontal'; - - const result = getNearestBlockIndex( - nonBlockElements, - position, - orientation - ); - - expect( result ).toBeUndefined(); - } ); - describe( 'Vertical block lists', () => { const orientation = 'vertical';