-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
index.js
56 lines (50 loc) · 1.57 KB
/
index.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
/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import BlockSwitcher from '../block-switcher';
import MultiBlocksSwitcher from '../block-switcher/multi-blocks-switcher';
import BlockControls from '../block-controls';
import BlockFormatControls from '../block-format-controls';
import BlockSettingsMenu from '../block-settings-menu';
function BlockToolbar( { blockClientIds, isValid, mode } ) {
if ( blockClientIds.length === 0 ) {
return null;
}
if ( blockClientIds.length > 1 ) {
return (
<div className="editor-block-toolbar block-editor-block-toolbar">
<MultiBlocksSwitcher />
<BlockSettingsMenu clientIds={ blockClientIds } />
</div>
);
}
return (
<div className="editor-block-toolbar block-editor-block-toolbar">
{ mode === 'visual' && isValid && (
<>
<BlockSwitcher clientIds={ blockClientIds } />
<BlockControls.Slot bubblesVirtually className="block-editor-block-toolbar__slot" />
<BlockFormatControls.Slot bubblesVirtually className="block-editor-block-toolbar__slot" />
</>
) }
<BlockSettingsMenu clientIds={ blockClientIds } />
</div>
);
}
export default withSelect( ( select ) => {
const {
getBlockMode,
getSelectedBlockClientIds,
isBlockValid,
} = select( 'core/block-editor' );
const blockClientIds = getSelectedBlockClientIds();
return {
blockClientIds,
isValid: blockClientIds.length === 1 ? isBlockValid( blockClientIds[ 0 ] ) : null,
mode: blockClientIds.length === 1 ? getBlockMode( blockClientIds[ 0 ] ) : null,
};
} )( BlockToolbar );