Skip to content

Commit

Permalink
Drag and drop: allow dragging to the beginning and end of a document (#…
Browse files Browse the repository at this point in the history
…56070)

* Try passing in a ref to allow dragging to the top and bottom of the editor canvas

* Update naming

* Implement in the site editor

* Fix gap between post title and top of iframe

* Add __unstable prefix in useInnerBlocksProps

* Fix typo in comment
  • Loading branch information
andrewserong committed Nov 17, 2023
1 parent 802c7a5 commit 178ca84
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/block-editor/src/components/inner-blocks/index.js
Expand Up @@ -169,8 +169,11 @@ const ForwardedInnerBlocks = forwardRef( ( props, ref ) => {
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/inner-blocks/README.md
*/
export function useInnerBlocksProps( props = {}, options = {} ) {
const { __unstableDisableLayoutClassNames, __unstableDisableDropZone } =
options;
const {
__unstableDisableLayoutClassNames,
__unstableDisableDropZone,
__unstableDropZoneElement,
} = options;
const {
clientId,
layout = null,
Expand Down Expand Up @@ -211,6 +214,7 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
);

const blockDropZoneRef = useBlockDropZone( {
dropZoneElement: __unstableDropZoneElement,
rootClientId: clientId,
} );

Expand Down
Expand Up @@ -127,7 +127,8 @@ export function getDropTargetPosition(

/**
* @typedef {Object} WPBlockDropZoneConfig
* @property {string} rootClientId The root client id for the block list.
* @property {?HTMLElement} dropZoneElement Optional element to be used as the drop zone.
* @property {string} rootClientId The root client id for the block list.
*/

/**
Expand All @@ -136,6 +137,7 @@ export function getDropTargetPosition(
* @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.
*/
export default function useBlockDropZone( {
dropZoneElement,
// An undefined value represents a top-level block. Default to an empty
// string for this so that `targetRootClientId` can be easily compared to
// values returned by the `getRootBlockClientId` selector, which also uses
Expand Down Expand Up @@ -235,6 +237,7 @@ export default function useBlockDropZone( {
);

return useDropZone( {
dropZoneElement,
isDisabled,
onDrop: onBlockDrop,
onDragOver( event ) {
Expand Down
7 changes: 7 additions & 0 deletions packages/edit-post/src/components/visual-editor/index.js
Expand Up @@ -411,6 +411,13 @@ export default function VisualEditor( { styles } ) {
: `${ blockListLayoutClass } wp-block-post-content` // Ensure root level blocks receive default/flow blockGap styling rules.
}
layout={ blockListLayout }
__unstableDropZoneElement={
// When iframed, pass in the html element of the iframe to
// ensure the drop zone extends to the edges of the iframe.
isToBeIframed
? ref.current?.parentNode
: ref.current
}
/>
</RecursionProvider>
</BlockCanvas>
Expand Down
Expand Up @@ -134,6 +134,12 @@ export default function SiteEditorCanvas() {
isTemplateTypeNavigation,
}
) }
__unstableDropZoneElement={
// Pass in the html element of the iframe to ensure that
// the drop zone extends to the very edges of the iframe,
// even if the template is shorter than the viewport.
contentRef.current?.parentNode
}
layout={ LAYOUT }
renderAppender={ showBlockAppender }
/>
Expand Down

0 comments on commit 178ca84

Please sign in to comment.