@wordpress/block-editor
Version:
43 lines (39 loc) • 1.31 kB
JavaScript
import { createElement, Fragment } from "@wordpress/element";
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import BlockControls from '../block-controls';
import UngroupButton from '../ungroup-button';
import { store as blockEditorStore } from '../../store';
export default function BlockToolbar() {
const {
isSelected,
isValidAndVisual
} = useSelect(select => {
const {
getBlockMode,
getSelectedBlockClientIds,
isBlockValid
} = select(blockEditorStore);
const selectedBlockClientIds = getSelectedBlockClientIds();
return {
isSelected: selectedBlockClientIds.length > 0,
isValidAndVisual: selectedBlockClientIds.length === 1 ? isBlockValid(selectedBlockClientIds[0]) && getBlockMode(selectedBlockClientIds[0]) === 'visual' : false
};
}, []);
if (!isSelected) {
return null;
}
return createElement(Fragment, null, isValidAndVisual && createElement(Fragment, null, createElement(UngroupButton, null), createElement(BlockControls.Slot, {
group: "block"
}), createElement(BlockControls.Slot, null), createElement(BlockControls.Slot, {
group: "inline"
}), createElement(BlockControls.Slot, {
group: "other"
})));
}
//# sourceMappingURL=index.native.js.map