@wordpress/block-library
Version:
Block library for the WordPress editor.
52 lines (49 loc) • 1.5 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = save;
var _clsx = _interopRequireDefault(require("clsx"));
var _blockEditor = require("@wordpress/block-editor");
var _jsxRuntime = require("react/jsx-runtime");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
function save({
attributes
}) {
const {
verticalAlignment,
width
} = attributes;
const wrapperClasses = (0, _clsx.default)({
[`is-vertically-aligned-${verticalAlignment}`]: verticalAlignment
});
let style;
if (width && /\d/.test(width)) {
// Numbers are handled for backward compatibility as they can be still provided with templates.
let flexBasis = Number.isFinite(width) ? width + '%' : width;
// In some cases we need to round the width to a shorter float.
if (!Number.isFinite(width) && width?.endsWith('%')) {
const multiplier = 1000000000000;
// Shrink the number back to a reasonable float.
flexBasis = Math.round(Number.parseFloat(width) * multiplier) / multiplier + '%';
}
style = {
flexBasis
};
}
const blockProps = _blockEditor.useBlockProps.save({
className: wrapperClasses,
style
});
const innerBlocksProps = _blockEditor.useInnerBlocksProps.save(blockProps);
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
...innerBlocksProps
});
}
//# sourceMappingURL=save.js.map
;