@gechiui/block-editor
Version:
91 lines (79 loc) • 3.56 kB
JavaScript
import { createElement } from "@gechiui/element";
/**
* GeChiUI dependencies
*/
import { getBlockSupport } from '@gechiui/blocks';
import { PanelBody } from '@gechiui/components';
import { Platform } from '@gechiui/element';
import { __ } from '@gechiui/i18n';
/**
* Internal dependencies
*/
import InspectorControls from '../components/inspector-controls';
import useSetting from '../components/use-setting';
import { BorderColorEdit } from './border-color';
import { BorderRadiusEdit } from './border-radius';
import { BorderStyleEdit } from './border-style';
import { BorderWidthEdit } from './border-width';
export const BORDER_SUPPORT_KEY = '__experimentalBorder';
export function BorderPanel(props) {
const isDisabled = useIsBorderDisabled(props);
const isSupported = hasBorderSupport(props.name);
const isColorSupported = useSetting('border.color') && hasBorderSupport(props.name, 'color');
const isRadiusSupported = useSetting('border.radius') && hasBorderSupport(props.name, 'radius');
const isStyleSupported = useSetting('border.style') && hasBorderSupport(props.name, 'style');
const isWidthSupported = useSetting('border.width') && hasBorderSupport(props.name, 'width');
if (isDisabled || !isSupported) {
return null;
}
return createElement(InspectorControls, null, createElement(PanelBody, {
className: "block-editor-hooks__border-controls",
title: __('边框'),
initialOpen: false
}, (isWidthSupported || isStyleSupported) && createElement("div", {
className: "block-editor-hooks__border-controls-row"
}, isWidthSupported && createElement(BorderWidthEdit, props), isStyleSupported && createElement(BorderStyleEdit, props)), isColorSupported && createElement(BorderColorEdit, props), isRadiusSupported && createElement(BorderRadiusEdit, props)));
}
/**
* Determine whether there is block support for border properties.
*
* @param {string} blockName Block name.
* @param {string} feature Border feature to check support for.
*
* @return {boolean} Whether there is support.
*/
export function hasBorderSupport(blockName) {
let feature = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'any';
if (Platform.OS !== 'web') {
return false;
}
const support = getBlockSupport(blockName, BORDER_SUPPORT_KEY);
if (support === true) {
return true;
}
if (feature === 'any') {
return !!(support !== null && support !== void 0 && support.color || support !== null && support !== void 0 && support.radius || support !== null && support !== void 0 && support.width || support !== null && support !== void 0 && support.style);
}
return !!(support !== null && support !== void 0 && support[feature]);
}
/**
* Check whether serialization of border classes and styles should be skipped.
*
* @param {string|Object} blockType Block name or block type object.
*
* @return {boolean} Whether serialization of border properties should occur.
*/
export function shouldSkipSerialization(blockType) {
const support = getBlockSupport(blockType, BORDER_SUPPORT_KEY);
return support === null || support === void 0 ? void 0 : support.__experimentalSkipSerialization;
}
/**
* Determines if all border support features have been disabled.
*
* @return {boolean} If border support is completely disabled.
*/
const useIsBorderDisabled = () => {
const configs = [!useSetting('border.color'), !useSetting('border.radius'), !useSetting('border.style'), !useSetting('border.width')];
return configs.every(Boolean);
};
//# sourceMappingURL=border.js.map