@wordpress/block-editor
Version:
51 lines (48 loc) • 1.8 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useShowBlockTools = useShowBlockTools;
var _data = require("@wordpress/data");
var _blocks = require("@wordpress/blocks");
var _store = require("../../store");
var _lockUnlock = require("../../lock-unlock");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Source of truth for which block tools are showing in the block editor.
*
* @return {Object} Object of which block tools will be shown.
*/
function useShowBlockTools() {
return (0, _data.useSelect)(select => {
const {
getSelectedBlockClientId,
getFirstMultiSelectedBlockClientId,
getBlock,
getBlockMode,
getSettings,
__unstableGetEditorMode,
isTyping
} = (0, _lockUnlock.unlock)(select(_store.store));
const clientId = getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId();
const block = getBlock(clientId);
const editorMode = __unstableGetEditorMode();
const hasSelectedBlock = !!clientId && !!block;
const isEmptyDefaultBlock = hasSelectedBlock && (0, _blocks.isUnmodifiedDefaultBlock)(block) && getBlockMode(clientId) !== 'html';
const _showEmptyBlockSideInserter = clientId && !isTyping() &&
// Hide the block inserter on the navigation mode.
// See https://github.com/WordPress/gutenberg/pull/66636#discussion_r1824728483.
editorMode !== 'navigation' && isEmptyDefaultBlock;
const _showBlockToolbarPopover = !getSettings().hasFixedToolbar && !_showEmptyBlockSideInserter && hasSelectedBlock && !isEmptyDefaultBlock;
return {
showEmptyBlockSideInserter: _showEmptyBlockSideInserter,
showBlockToolbarPopover: _showBlockToolbarPopover
};
}, []);
}
//# sourceMappingURL=use-show-block-tools.js.map
;