@gechiui/block-editor
Version:
77 lines (70 loc) • 1.9 kB
JavaScript
import { createElement } from "@gechiui/element";
/**
* External dependencies
*/
import { noop } from 'lodash';
/**
* GeChiUI dependencies
*/
import { store as blocksStore } from '@gechiui/blocks';
import { ToolbarGroup, ToolbarButton } from '@gechiui/components';
import { __ } from '@gechiui/i18n';
import { withSelect, withDispatch } from '@gechiui/data';
import { compose } from '@gechiui/compose';
/**
* Internal dependencies
*/
import UngroupIcon from './icon';
import { store as blockEditorStore } from '../../store';
export function UngroupButton(_ref) {
let {
onConvertFromGroup,
isUngroupable = false
} = _ref;
if (!isUngroupable) {
return null;
}
return createElement(ToolbarGroup, null, createElement(ToolbarButton, {
title: __('Ungroup'),
icon: UngroupIcon,
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 && selectedBlock.name === groupingBlockName;
const innerBlocks = isUngroupable ? selectedBlock.innerBlocks : [];
return {
isUngroupable,
clientId: selectedId,
innerBlocks
};
}), withDispatch((dispatch, _ref2) => {
let {
clientId,
innerBlocks,
onToggle = noop
} = _ref2;
const {
replaceBlocks
} = dispatch(blockEditorStore);
return {
onConvertFromGroup() {
if (!innerBlocks.length) {
return;
}
replaceBlocks(clientId, innerBlocks);
onToggle();
}
};
})])(UngroupButton);
//# sourceMappingURL=index.native.js.map