@wordpress/block-editor
Version:
69 lines (61 loc) • 1.93 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { createElement } from "@wordpress/element";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { hasBlockSupport, store as blocksStore } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import NavigableToolbar from '../navigable-toolbar';
import { BlockToolbar } from '../';
import { store as blockEditorStore } from '../../store';
function BlockContextualToolbar({
focusOnMount,
...props
}) {
const {
blockType,
hasParents
} = useSelect(select => {
const {
getBlockName,
getBlockParents,
getSelectedBlockClientIds
} = select(blockEditorStore);
const {
getBlockType
} = select(blocksStore);
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[0];
return {
blockType: selectedBlockClientId && getBlockType(getBlockName(selectedBlockClientId)),
hasParents: getBlockParents(selectedBlockClientId).length
};
}, []);
if (blockType) {
if (!hasBlockSupport(blockType, '__experimentalToolbar', true)) {
return null;
}
} // Shifts the toolbar to make room for the parent block selector.
const classes = classnames('block-editor-block-contextual-toolbar', {
'has-parent': hasParents
});
return createElement("div", {
className: "block-editor-block-contextual-toolbar-wrapper"
}, createElement(NavigableToolbar, _extends({
focusOnMount: focusOnMount,
className: classes
/* translators: accessibility text for the block toolbar */
,
"aria-label": __('Block tools')
}, props), createElement(BlockToolbar, null)));
}
export default BlockContextualToolbar;
//# sourceMappingURL=block-contextual-toolbar.js.map