Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Keep inserters visible on scroll
  • Loading branch information
youknowriad committed May 19, 2022
commit 232b6f9e46e25f23ffeb4c19d15651eef5029f1e
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ function BlockPopoverInbetween( {
width,
height: previousRect ? previousRect.height : nextRect.height,
};
}, [ previousElement, nextElement, isVertical, positionRecompute ] );
}, [
previousElement,
nextElement,
isVertical,
positionRecompute,
isVisible,
] );

const getAnchorRect = useCallback( () => {
if ( ( ! previousElement && ! nextElement ) || ! isVisible ) {
Expand Down Expand Up @@ -159,7 +165,7 @@ function BlockPopoverInbetween( {
width: 0,
ownerDocument,
};
}, [ previousElement, nextElement, positionRecompute ] );
}, [ previousElement, nextElement, positionRecompute, isVisible ] );

const popoverScrollRef = usePopoverScroll( __unstableContentRef );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// like the popover is impacted by the block gap margin.
margin: 0 !important;

// Allow clicking through the toolbar holder.
pointer-events: none;

.components-popover__content {
margin: 0 !important;
min-width: auto;
Expand All @@ -16,8 +19,6 @@
box-shadow: none;
overflow-y: visible;

// Allow clicking through the toolbar holder.
pointer-events: none;
> div > * {
pointer-events: all;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,20 @@
/**
* External dependencies
*/
import { throttle } from 'lodash';

/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useState, useEffect } from '@wordpress/element';

/**
* Internal dependencies
*/
import BlockPopoverInbetween from '../block-popover/inbetween';
import { store as blockEditorStore } from '../../store';
import Inserter from '../inserter';
import { __unstableUseBlockElement } from '../block-list/use-block-props/use-block-refs';

function useIsScrolling() {
const [ isScrolling, setIsScrolling ] = useState( false );

const clientId = useSelect( ( select ) => {
return select( blockEditorStore ).getBlockOrder()?.[ 0 ];
}, [] );
const element = __unstableUseBlockElement( clientId );

useEffect( () => {
let timeout;
setIsScrolling( false );
if ( ! element ) {
return;
}
const onScroll = throttle( () => {
setIsScrolling( true );
clearTimeout( timeout );
timeout = setTimeout( () => {
setIsScrolling( false );
}, 100 );
}, 100 );

element.ownerDocument.defaultView.addEventListener(
'scroll',
onScroll
);
return () => {
clearTimeout( timeout );
element.ownerDocument.defaultView.removeEventListener(
'scroll',
onScroll
);
};
}, [ element ] );

return isScrolling;
}

function ExplodedModeInserters( { __unstableContentRef } ) {
const isScrolling = useIsScrolling();
const blockOrder = useSelect( ( select ) => {
return select( blockEditorStore ).getBlockOrder();
}, [] );

if ( isScrolling ) {
return null;
}

return blockOrder.map( ( clientId, index ) => {
if ( index === blockOrder.length - 1 ) {
return null;
Expand Down