@gechiui/block-editor
Version:
101 lines (91 loc) • 3.02 kB
JavaScript
import { createElement } from "@gechiui/element";
/**
* GeChiUI dependencies
*/
import { hasBlockSupport } from '@gechiui/blocks';
/**
* Internal dependencies
*/
import LineHeightControl from '../components/line-height-control';
import { cleanEmptyObject } from './utils';
import useSetting from '../components/use-setting';
export const LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';
/**
* Inspector control panel containing the line height related configuration
*
* @param {Object} props
*
* @return {GCElement} Line height edit element.
*/
export function LineHeightEdit(props) {
var _style$typography;
const {
attributes: {
style
},
setAttributes
} = props;
const onChange = newLineHeightValue => {
const newStyle = { ...style,
typography: { ...(style === null || style === void 0 ? void 0 : style.typography),
lineHeight: newLineHeightValue
}
};
setAttributes({
style: cleanEmptyObject(newStyle)
});
};
return createElement(LineHeightControl, {
value: style === null || style === void 0 ? void 0 : (_style$typography = style.typography) === null || _style$typography === void 0 ? void 0 : _style$typography.lineHeight,
onChange: onChange
});
}
/**
* Custom hook that checks if line-height settings have been disabled.
*
* @param {string} name The name of the block.
* @return {boolean} Whether setting is disabled.
*/
export function useIsLineHeightDisabled() {
let {
name: blockName
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const isDisabled = !useSetting('typography.lineHeight');
return !hasBlockSupport(blockName, LINE_HEIGHT_SUPPORT_KEY) || isDisabled;
}
/**
* Checks if there is a current value set for the line height block support.
*
* @param {Object} props Block props.
* @return {boolean} Whether or not the block has a line height value set.
*/
export function hasLineHeightValue(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.lineHeight);
}
/**
* Resets the line height block support attribute. This can be used when
* disabling the line height 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.
*/
export function resetLineHeight(_ref) {
let {
attributes = {},
setAttributes
} = _ref;
const {
style
} = attributes;
setAttributes({
style: cleanEmptyObject({ ...style,
typography: { ...(style === null || style === void 0 ? void 0 : style.typography),
lineHeight: undefined
}
})
});
}
//# sourceMappingURL=line-height.js.map