@gechiui/block-editor
Version:
78 lines (70 loc) • 2.32 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { createElement } from "@gechiui/element";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* GeChiUI dependencies
*/
import { __ } from '@gechiui/i18n';
import { hasBlockSupport, store as blocksStore } from '@gechiui/blocks';
import { useSelect } from '@gechiui/data';
/**
* Internal dependencies
*/
import NavigableToolbar from '../navigable-toolbar';
import BlockToolbar from '../block-toolbar';
import { store as blockEditorStore } from '../../store';
function BlockContextualToolbar(_ref) {
let {
focusOnMount,
isFixed,
...props
} = _ref;
const {
blockType,
hasParents,
showParentSelector
} = useSelect(select => {
const {
getBlockName,
getBlockParents,
getSelectedBlockClientIds
} = select(blockEditorStore);
const {
getBlockType
} = select(blocksStore);
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[0];
const parents = getBlockParents(selectedBlockClientId);
const firstParentClientId = parents[parents.length - 1];
const parentBlockName = getBlockName(firstParentClientId);
const parentBlockType = getBlockType(parentBlockName);
return {
blockType: selectedBlockClientId && getBlockType(getBlockName(selectedBlockClientId)),
hasParents: parents.length,
showParentSelector: hasBlockSupport(parentBlockType, '__experimentalParentSelector', true) && selectedBlockClientIds.length <= 1
};
}, []);
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 && showParentSelector,
'is-fixed': isFixed
});
return createElement(NavigableToolbar, _extends({
focusOnMount: focusOnMount,
className: classes
/* translators: accessibility text for the block toolbar */
,
"aria-label": __('区块工具')
}, props), createElement(BlockToolbar, {
hideDragHandle: isFixed
}));
}
export default BlockContextualToolbar;
//# sourceMappingURL=block-contextual-toolbar.js.map