@wordpress/block-editor
Version:
8 lines (7 loc) • 1.64 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/block-toolbar/use-has-block-toolbar.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { getBlockType, hasBlockSupport } from '@wordpress/blocks';\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the block toolbar should be shown.\n *\n * @return {boolean} Whether the block toolbar component will be rendered.\n */\nexport function useHasBlockToolbar() {\n\tconst enabled = useSelect( ( select ) => {\n\t\tconst { getBlockEditingMode, getBlockName, getBlockSelectionStart } =\n\t\t\tselect( blockEditorStore );\n\n\t\t// we only care about the 1st selected block\n\t\t// for the toolbar, so we use getBlockSelectionStart\n\t\t// instead of getSelectedBlockClientIds\n\t\tconst selectedBlockClientId = getBlockSelectionStart();\n\n\t\tconst blockType =\n\t\t\tselectedBlockClientId &&\n\t\t\tgetBlockType( getBlockName( selectedBlockClientId ) );\n\n\t\treturn (\n\t\t\tblockType &&\n\t\t\thasBlockSupport( blockType, '__experimentalToolbar', true ) &&\n\t\t\tgetBlockEditingMode( selectedBlockClientId ) !== 'disabled'\n\t\t);\n\t}, [] );\n\n\treturn enabled;\n}\n"],
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,cAAc,uBAAuB;AAI9C,SAAS,SAAS,wBAAwB;AAOnC,SAAS,qBAAqB;AACpC,QAAM,UAAU,UAAW,CAAE,WAAY;AACxC,UAAM,EAAE,qBAAqB,cAAc,uBAAuB,IACjE,OAAQ,gBAAiB;AAK1B,UAAM,wBAAwB,uBAAuB;AAErD,UAAM,YACL,yBACA,aAAc,aAAc,qBAAsB,CAAE;AAErD,WACC,aACA,gBAAiB,WAAW,yBAAyB,IAAK,KAC1D,oBAAqB,qBAAsB,MAAM;AAAA,EAEnD,GAAG,CAAC,CAAE;AAEN,SAAO;AACR;",
"names": []
}