@gechiui/block-editor
Version:
161 lines (143 loc) • 5.24 kB
JavaScript
import { createElement } from "@gechiui/element";
/**
* GeChiUI dependencies
*/
import { __ } from '@gechiui/i18n';
import { getBlockType, getUnregisteredTypeHandlerName, hasBlockSupport, store as blocksStore } from '@gechiui/blocks';
import { PanelBody, __experimentalUseSlot as useSlot } from '@gechiui/components';
import { useSelect } from '@gechiui/data';
/**
* Internal dependencies
*/
import SkipToSelectedBlock from '../skip-to-selected-block';
import BlockCard from '../block-card';
import { default as InspectorControls, InspectorAdvancedControls } from '../inspector-controls';
import BlockStyles from '../block-styles';
import MultiSelectionInspector from '../multi-selection-inspector';
import DefaultStylePicker from '../default-style-picker';
import BlockVariationTransforms from '../block-variation-transforms';
import useBlockDisplayInformation from '../use-block-display-information';
import { store as blockEditorStore } from '../../store';
const BlockInspector = _ref => {
let {
showNoBlockSelectedMessage = true,
bubblesVirtually = true
} = _ref;
const {
count,
hasBlockStyles,
selectedBlockName,
selectedBlockClientId,
blockType
} = useSelect(select => {
const {
getSelectedBlockClientId,
getSelectedBlockCount,
getBlockName
} = select(blockEditorStore);
const {
getBlockStyles
} = select(blocksStore);
const _selectedBlockClientId = getSelectedBlockClientId();
const _selectedBlockName = _selectedBlockClientId && getBlockName(_selectedBlockClientId);
const _blockType = _selectedBlockName && getBlockType(_selectedBlockName);
const blockStyles = _selectedBlockName && getBlockStyles(_selectedBlockName);
return {
count: getSelectedBlockCount(),
selectedBlockClientId: _selectedBlockClientId,
selectedBlockName: _selectedBlockName,
blockType: _blockType,
hasBlockStyles: blockStyles && blockStyles.length > 0
};
}, []);
if (count > 1) {
return createElement("div", {
className: "block-editor-block-inspector"
}, createElement(MultiSelectionInspector, null), createElement(InspectorControls.Slot, null), createElement(InspectorControls.Slot, {
__experimentalGroup: "typography",
label: __('排版')
}), createElement(InspectorControls.Slot, {
__experimentalGroup: "dimensions",
label: __('尺寸')
}), createElement(InspectorControls.Slot, {
__experimentalGroup: "border",
label: __('边框')
}));
}
const isSelectedBlockUnregistered = selectedBlockName === getUnregisteredTypeHandlerName();
/*
* If the selected block is of an unregistered type, avoid showing it as an actual selection
* because we want the user to focus on the unregistered block warning, not block settings.
*/
if (!blockType || !selectedBlockClientId || isSelectedBlockUnregistered) {
if (showNoBlockSelectedMessage) {
return createElement("span", {
className: "block-editor-block-inspector__no-blocks"
}, __('未选择区块。'));
}
return null;
}
return createElement(BlockInspectorSingleBlock, {
clientId: selectedBlockClientId,
blockName: blockType.name,
hasBlockStyles: hasBlockStyles,
bubblesVirtually: bubblesVirtually
});
};
const BlockInspectorSingleBlock = _ref2 => {
let {
clientId,
blockName,
hasBlockStyles,
bubblesVirtually
} = _ref2;
const blockInformation = useBlockDisplayInformation(clientId);
return createElement("div", {
className: "block-editor-block-inspector"
}, createElement(BlockCard, blockInformation), createElement(BlockVariationTransforms, {
blockClientId: clientId
}), hasBlockStyles && createElement("div", null, createElement(PanelBody, {
title: __('样式')
}, createElement(BlockStyles, {
clientId: clientId
}), hasBlockSupport(blockName, 'defaultStylePicker', true) && createElement(DefaultStylePicker, {
blockName: blockName
}))), createElement(InspectorControls.Slot, {
bubblesVirtually: bubblesVirtually
}), createElement(InspectorControls.Slot, {
__experimentalGroup: "typography",
bubblesVirtually: bubblesVirtually,
label: __('排版')
}), createElement(InspectorControls.Slot, {
__experimentalGroup: "dimensions",
bubblesVirtually: bubblesVirtually,
label: __('尺寸')
}), createElement(InspectorControls.Slot, {
__experimentalGroup: "border",
label: __('边框')
}), createElement("div", null, createElement(AdvancedControls, {
bubblesVirtually: bubblesVirtually
})), createElement(SkipToSelectedBlock, {
key: "back"
}));
};
const AdvancedControls = _ref3 => {
let {
bubblesVirtually
} = _ref3;
const slot = useSlot(InspectorAdvancedControls.slotName);
const hasFills = Boolean(slot.fills && slot.fills.length);
if (!hasFills) {
return null;
}
return createElement(PanelBody, {
className: "block-editor-block-inspector__advanced",
title: __('高级'),
initialOpen: false
}, createElement(InspectorControls.Slot, {
__experimentalGroup: "advanced",
bubblesVirtually: bubblesVirtually
}));
};
export default BlockInspector;
//# sourceMappingURL=index.js.map