From a11bfa4628dba84f6aae05fd1912264526ad3d53 Mon Sep 17 00:00:00 2001 From: apeatling Date: Wed, 6 Apr 2022 13:10:24 -0700 Subject: [PATCH 1/2] Initial experimentation with drop zones when hovering over an empty block. --- .../src/components/use-block-drop-zone/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 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 f9edab72733537..c5dd496c003b4e 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 @@ -112,16 +112,25 @@ export default function useBlockDropZone( { // Ensure the element is a block. It should have the `wp-block` class. ( element ) => element.classList.contains( 'wp-block' ) ); + const targetBlock = () => { + if ( event.srcElement.dataset?.empty === 'true' ) { + return event.target; + } + + return false; + }; const targetIndex = getNearestBlockIndex( blockElements, { x: event.clientX, y: event.clientY }, getBlockListSettings( targetRootClientId )?.orientation ); - setTargetBlockIndex( targetIndex === undefined ? 0 : targetIndex ); + if ( ! targetBlock() ) { + setTargetBlockIndex( targetIndex === undefined ? 0 : targetIndex ); - if ( targetIndex !== null ) { - showInsertionPoint( targetRootClientId, targetIndex ); + if ( targetIndex !== null ) { + showInsertionPoint( targetRootClientId, targetIndex ); + } } }, [] ), 200 From 704779297cc0a2f19e5d314b36dc2ff3c6e9b348 Mon Sep 17 00:00:00 2001 From: apeatling Date: Wed, 20 Apr 2022 08:57:12 -0700 Subject: [PATCH 2/2] Linter --- .../block-editor/src/components/use-block-drop-zone/index.js | 4 +++- 1 file changed, 3 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 c5dd496c003b4e..227526dad195cd 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 @@ -126,7 +126,9 @@ export default function useBlockDropZone( { ); if ( ! targetBlock() ) { - setTargetBlockIndex( targetIndex === undefined ? 0 : targetIndex ); + setTargetBlockIndex( + targetIndex === undefined ? 0 : targetIndex + ); if ( targetIndex !== null ) { showInsertionPoint( targetRootClientId, targetIndex );