Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor dropzone for unmodified default blocks with `useBlockDropZon…
…e` and `InsertionPoint` (#44647) * Try integrating block-popover-drop-zone with insertion-point * Fix changelog * Fix animation and add e2e tests * Remove fake html draggable once the drag starts * Address minor reviews * Add back deleted tests * Merge getNearestBlockIndex and getDropTargetIndexAndOperation * Add comment for insertion point
- Loading branch information
1 parent
fc081cc
commit 96e5dc7
Showing
24 changed files
with
1,053 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/block-editor/src/components/block-popover/drop-zone.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { useReducedMotion } from '@wordpress/compose'; | ||
import { __unstableMotion as motion } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import BlockPopover from './index'; | ||
|
||
const animateVariants = { | ||
hide: { opacity: 0, scaleY: 0.75 }, | ||
show: { opacity: 1, scaleY: 1 }, | ||
exit: { opacity: 0, scaleY: 0.9 }, | ||
}; | ||
|
||
function BlockDropZonePopover( { | ||
__unstablePopoverSlot, | ||
__unstableContentRef, | ||
} ) { | ||
const { clientId } = useSelect( ( select ) => { | ||
const { getBlockOrder, getBlockInsertionPoint } = | ||
select( blockEditorStore ); | ||
const insertionPoint = getBlockInsertionPoint(); | ||
const order = getBlockOrder( insertionPoint.rootClientId ); | ||
|
||
if ( ! order.length ) { | ||
return {}; | ||
} | ||
|
||
return { | ||
clientId: order[ insertionPoint.index ], | ||
}; | ||
}, [] ); | ||
const reducedMotion = useReducedMotion(); | ||
|
||
return ( | ||
<BlockPopover | ||
clientId={ clientId } | ||
__unstableCoverTarget | ||
__unstablePopoverSlot={ __unstablePopoverSlot } | ||
__unstableContentRef={ __unstableContentRef } | ||
className="block-editor-block-popover__drop-zone" | ||
> | ||
<motion.div | ||
data-testid="block-popover-drop-zone" | ||
initial={ | ||
reducedMotion ? animateVariants.show : animateVariants.hide | ||
} | ||
animate={ animateVariants.show } | ||
exit={ | ||
reducedMotion ? animateVariants.show : animateVariants.exit | ||
} | ||
className="block-editor-block-popover__drop-zone-foreground" | ||
/> | ||
</BlockPopover> | ||
); | ||
} | ||
|
||
export default BlockDropZonePopover; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.