-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathzoom-out-mode-inserters.js
57 lines (51 loc) · 1.39 KB
/
zoom-out-mode-inserters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import BlockPopoverInbetween from '../block-popover/inbetween';
import { store as blockEditorStore } from '../../store';
import Inserter from '../inserter';
function ZoomOutModeInserters( { __unstableContentRef } ) {
const [ isReady, setIsReady ] = useState( false );
const blockOrder = useSelect( ( select ) => {
return select( blockEditorStore ).getBlockOrder();
}, [] );
// Defer the initial rendering to avoid the jumps due to the animation.
useEffect( () => {
const timeout = setTimeout( () => {
setIsReady( true );
}, 500 );
return () => {
clearTimeout( timeout );
};
}, [] );
if ( ! isReady ) {
return null;
}
return blockOrder.map( ( clientId, index ) => {
if ( index === blockOrder.length - 1 ) {
return null;
}
return (
<BlockPopoverInbetween
key={ clientId }
previousClientId={ clientId }
nextClientId={ blockOrder[ index + 1 ] }
__unstableContentRef={ __unstableContentRef }
>
<div className="block-editor-block-list__insertion-point-inserter is-with-inserter">
<Inserter
position="bottom center"
clientId={ blockOrder[ index + 1 ] }
__experimentalIsQuick
/>
</div>
</BlockPopoverInbetween>
);
} );
}
export default ZoomOutModeInserters;