UNPKG

@wordpress/block-editor

Version:
69 lines (68 loc) 1.89 kB
/** * WordPress dependencies */ import { store as blocksStore } from '@wordpress/blocks'; import { ToolbarGroup, ToolbarButton } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { withSelect, withDispatch } from '@wordpress/data'; import { compose } from '@wordpress/compose'; import { ungroup } from '@wordpress/icons'; /** * Internal dependencies */ import { store as blockEditorStore } from '../../store'; import { jsx as _jsx } from "react/jsx-runtime"; const noop = () => {}; const EMPTY_BLOCKS_LIST = []; export function UngroupButton({ onConvertFromGroup, isUngroupable = false }) { if (!isUngroupable) { return null; } return /*#__PURE__*/_jsx(ToolbarGroup, { children: /*#__PURE__*/_jsx(ToolbarButton, { title: __('Ungroup'), icon: ungroup, onClick: onConvertFromGroup }) }); } export default compose([withSelect(select => { const { getSelectedBlockClientId, getBlock } = select(blockEditorStore); const { getGroupingBlockName } = select(blocksStore); const selectedId = getSelectedBlockClientId(); const selectedBlock = getBlock(selectedId); const groupingBlockName = getGroupingBlockName(); const isUngroupable = selectedBlock && selectedBlock.innerBlocks && selectedBlock.innerBlocks.length > 0 && selectedBlock.name === groupingBlockName; const innerBlocks = isUngroupable ? selectedBlock.innerBlocks : EMPTY_BLOCKS_LIST; return { isUngroupable, clientId: selectedId, innerBlocks }; }), withDispatch((dispatch, { clientId, innerBlocks, onToggle = noop }) => { const { replaceBlocks } = dispatch(blockEditorStore); return { onConvertFromGroup() { if (!innerBlocks.length) { return; } replaceBlocks(clientId, innerBlocks); onToggle(); } }; })])(UngroupButton); //# sourceMappingURL=index.native.js.map