@wordpress/block-editor
Version:
89 lines (71 loc) • 2.5 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TextDecorationEdit = TextDecorationEdit;
exports.useIsTextDecorationDisabled = useIsTextDecorationDisabled;
exports.TEXT_DECORATION_SUPPORT_KEY = void 0;
var _element = require("@wordpress/element");
var _blocks = require("@wordpress/blocks");
var _textDecorationControl = _interopRequireDefault(require("../components/text-decoration-control"));
var _useEditorFeature = _interopRequireDefault(require("../components/use-editor-feature"));
var _utils = require("./utils");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Key within block settings' supports array indicating support for text
* decorations e.g. settings found in `block.json`.
*/
const TEXT_DECORATION_SUPPORT_KEY = '__experimentalTextDecoration';
/**
* Inspector control panel containing the text decoration options.
*
* @param {Object} props Block properties.
* @return {WPElement} Text decoration edit element.
*/
exports.TEXT_DECORATION_SUPPORT_KEY = TEXT_DECORATION_SUPPORT_KEY;
function TextDecorationEdit(props) {
var _style$typography;
const {
attributes: {
style
},
setAttributes
} = props;
const isDisabled = useIsTextDecorationDisabled(props);
if (isDisabled) {
return null;
}
function onChange(newDecoration) {
setAttributes({
style: (0, _utils.cleanEmptyObject)({ ...style,
typography: { ...(style === null || style === void 0 ? void 0 : style.typography),
textDecoration: newDecoration
}
})
});
}
return (0, _element.createElement)(_textDecorationControl.default, {
value: style === null || style === void 0 ? void 0 : (_style$typography = style.typography) === null || _style$typography === void 0 ? void 0 : _style$typography.textDecoration,
onChange: onChange
});
}
/**
* Checks if text-decoration settings have been disabled.
*
* @param {string} name Name of the block.
* @return {boolean} Whether or not the setting is disabled.
*/
function useIsTextDecorationDisabled({
name: blockName
} = {}) {
const notSupported = !(0, _blocks.hasBlockSupport)(blockName, TEXT_DECORATION_SUPPORT_KEY);
const hasTextDecoration = (0, _useEditorFeature.default)('typography.customTextDecorations');
return notSupported || !hasTextDecoration;
}
//# sourceMappingURL=text-decoration.js.map