Skip to content

Commit

Permalink
Remove function that checks if a row or gallery can be created
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Aug 6, 2024
1 parent dab48cd commit a6b515a
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions packages/block-editor/src/components/use-block-drop-zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,6 @@ export function isDropTargetValid(
return areBlocksAllowed && targetMatchesDraggedBlockParents;
}

/**
* Check if the Row or the Gallery can be created with the dragged
* blocks and the target block.
* @param {boolean} areAllImages
* @param {boolean} canInsertGalleryBlock
* @param {boolean} areGroupableBlocks
* @param {boolean} canInsertRow
* @return {boolean} Whether Row block or Gallery can be created.
*/
function canCreateRowOrGallery(
areAllImages,
canInsertGalleryBlock,
areGroupableBlocks,
canInsertRow
) {
if ( areAllImages ) {
return canInsertGalleryBlock || ( areGroupableBlocks && canInsertRow );
}
return areGroupableBlocks && canInsertRow;
}

/**
* @typedef {Object} WPBlockDropZoneConfig
* @property {?HTMLElement} dropZoneElement Optional element to be used as the drop zone.
Expand Down Expand Up @@ -427,8 +406,6 @@ export default function useBlockDropZone( {
const [ targetIndex, operation, nearestSide ] =
dropTargetPosition;

// Checks if it is creatable either a Row variation or a Gallery block from
// the dragged block and the target block.
if ( operation === 'group' ) {
const targetBlock = blocks[ targetIndex ];
const areAllImages = [
Expand All @@ -452,13 +429,22 @@ export default function useBlockDropZone( {
groupBlockVariations.find(
( { name } ) => name === 'group-row'
);
const _canCreateRowOrGallery = canCreateRowOrGallery(
areAllImages,
canInsertGalleryBlock,
areGroupableBlocks,
canInsertRow
);
if ( ! _canCreateRowOrGallery ) {

// If the dragged blocks and the target block are all images,
// check if it is creatable either a Row variation or a Gallery block.
if (
areAllImages &&
! canInsertGalleryBlock &&
( ! areGroupableBlocks || ! canInsertRow )
) {
return;
}
// If the dragged blocks and the target block are not all images,
// check if it is creatable a Row variation.
if (
! areAllImages &&
( ! areGroupableBlocks || ! canInsertRow )
) {
return;
}
}
Expand Down

0 comments on commit a6b515a

Please sign in to comment.