UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 1.69 kB
{ "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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,oBAA8C;AAI9C,mBAA0C;AAOnC,SAAS,qBAAqB;AACpC,QAAM,cAAU,uBAAW,CAAE,WAAY;AACxC,UAAM,EAAE,qBAAqB,cAAc,uBAAuB,IACjE,OAAQ,aAAAA,KAAiB;AAK1B,UAAM,wBAAwB,uBAAuB;AAErD,UAAM,YACL,6BACA,4BAAc,aAAc,qBAAsB,CAAE;AAErD,WACC,iBACA,+BAAiB,WAAW,yBAAyB,IAAK,KAC1D,oBAAqB,qBAAsB,MAAM;AAAA,EAEnD,GAAG,CAAC,CAAE;AAEN,SAAO;AACR;", "names": ["blockEditorStore"] }