Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"@types/highlight-words-core": "1.2.1",
"@types/istanbul-lib-report": "3.0.0",
"@types/lodash": "4.14.172",
"@types/mime": "2.0.3",
"@types/npm-package-arg": "6.1.1",
"@types/prettier": "2.4.4",
"@types/qs": "6.9.7",
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export {
export { default as __experimentalBlockPatternsList } from './block-patterns-list';
export { default as __experimentalPublishDateTimePicker } from './publish-date-time-picker';
export { default as __experimentalInspectorPopoverHeader } from './inspector-popover-header';
export { default as __experimentalUseOnBlockDrop } from './use-on-block-drop';

@ellatrix ellatrix Sep 28, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mark this unstable/internal? I don't think this is an API that we want to expose in this shape.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I don't mind changing it to __internal or any other naming. I only use __experimental here because that's a more established pattern.


/*
* State Related Components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ export function getNearestBlockIndex( elements, position, orientation ) {
return candidateIndex;
}

/**
* Determine if the element is an empty paragraph block.
*
* @param {?HTMLElement} element The element being tested.
* @return {boolean} True or False.
*/
function isEmptyParagraph( element ) {
return (
!! element &&
element.dataset.type === 'core/paragraph' &&
element.dataset.empty === 'true'
);
}

/**
* @typedef {Object} WPBlockDropZoneConfig
* @property {string} rootClientId The root client id for the block list.
Expand Down Expand Up @@ -130,7 +144,18 @@ export default function useBlockDropZone( {

setTargetBlockIndex( targetIndex === undefined ? 0 : targetIndex );

if ( targetIndex !== null ) {
if ( targetIndex !== undefined ) {
const nextBlock = blockElements[ targetIndex ];
const previousBlock = blockElements[ targetIndex - 1 ];

// Don't show the insertion point when it's near an empty paragraph block.
if (
isEmptyParagraph( nextBlock ) ||
isEmptyParagraph( previousBlock )
) {
return;
}

showInsertionPoint( targetRootClientId, targetIndex );
}
}, [] ),
Expand Down
Loading