@gechiui/block-editor
Version:
129 lines (107 loc) • 3.81 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TEXT_TRANSFORM_SUPPORT_KEY = void 0;
exports.TextTransformEdit = TextTransformEdit;
exports.hasTextTransformValue = hasTextTransformValue;
exports.resetTextTransform = resetTextTransform;
exports.useIsTextTransformDisabled = useIsTextTransformDisabled;
var _element = require("@gechiui/element");
var _blocks = require("@gechiui/blocks");
var _textTransformControl = _interopRequireDefault(require("../components/text-transform-control"));
var _useSetting = _interopRequireDefault(require("../components/use-setting"));
var _utils = require("./utils");
/**
* GeChiUI dependencies
*/
/**
* Internal dependencies
*/
/**
* Key within block settings' supports array indicating support for text
* transforms e.g. settings found in `block.json`.
*/
const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
/**
* Inspector control panel containing the text transform options.
*
* @param {Object} props Block properties.
*
* @return {GCElement} Text transform edit element.
*/
exports.TEXT_TRANSFORM_SUPPORT_KEY = TEXT_TRANSFORM_SUPPORT_KEY;
function TextTransformEdit(props) {
var _style$typography;
const {
attributes: {
style
},
setAttributes
} = props;
function onChange(newTransform) {
setAttributes({
style: (0, _utils.cleanEmptyObject)({ ...style,
typography: { ...(style === null || style === void 0 ? void 0 : style.typography),
textTransform: newTransform
}
})
});
}
return (0, _element.createElement)(_textTransformControl.default, {
value: style === null || style === void 0 ? void 0 : (_style$typography = style.typography) === null || _style$typography === void 0 ? void 0 : _style$typography.textTransform,
onChange: onChange
});
}
/**
* Checks if text-transform settings have been disabled.
*
* @param {string} name Name of the block.
*
* @return {boolean} Whether or not the setting is disabled.
*/
function useIsTextTransformDisabled() {
let {
name: blockName
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const notSupported = !(0, _blocks.hasBlockSupport)(blockName, TEXT_TRANSFORM_SUPPORT_KEY);
const hasTextTransforms = (0, _useSetting.default)('typography.textTransform');
return notSupported || !hasTextTransforms;
}
/**
* Checks if there is a current value set for the text transform block support.
*
* @param {Object} props Block props.
* @return {boolean} Whether or not the block has a text transform set.
*/
function hasTextTransformValue(props) {
var _props$attributes$sty, _props$attributes$sty2;
return !!((_props$attributes$sty = props.attributes.style) !== null && _props$attributes$sty !== void 0 && (_props$attributes$sty2 = _props$attributes$sty.typography) !== null && _props$attributes$sty2 !== void 0 && _props$attributes$sty2.textTransform);
}
/**
* Resets the text transform block support attribute. This can be used when
* disabling the text transform support controls for a block via a progressive
* discovery panel.
*
* @param {Object} props Block props.
* @param {Object} props.attributes Block's attributes.
* @param {Object} props.setAttributes Function to set block's attributes.
*/
function resetTextTransform(_ref) {
let {
attributes = {},
setAttributes
} = _ref;
const {
style
} = attributes;
setAttributes({
style: (0, _utils.cleanEmptyObject)({ ...style,
typography: { ...(style === null || style === void 0 ? void 0 : style.typography),
textTransform: undefined
}
})
});
}
//# sourceMappingURL=text-transform.js.map