@wordpress/block-library
Version:
Block library for the WordPress editor.
86 lines (85 loc) • 2.89 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_blocks = require("@wordpress/blocks");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_block_editor = require("@wordpress/block-editor");
// packages/block-library/src/post-author/utils.js
const { cleanEmptyObject } = (0, require("../lock-unlock.cjs").unlock)(_wordpress_block_editor.privateApis);
/**
* Generate Author-related blocks based on block attributes.
*
* @param {Object} attributes Block's attributes.
* @param {Object} blockTypes Block types.
* @return {Object} Generated block.
*/
function recreateWithRecommendedBlocks(attributes, blockTypes) {
const { avatarSize, byline, showAvatar, showBio, isLink, linkTarget, textAlign, style, ...restAttributes } = attributes;
const shouldInsertAvatarBlock = showAvatar && blockTypes.some((blockType) => blockType.name === "core/avatar");
const shouldInsertParagraphBlock = byline && blockTypes.some((blockType) => blockType.name === "core/paragraph");
const shouldInsertPostAuthorNameBlock = blockTypes.some((blockType) => blockType.name === "core/post-author-name");
const shouldInsertPostAuthorBiographyBlock = showBio && blockTypes.some((blockType) => blockType.name === "core/post-author-biography");
return (0, _wordpress_blocks.createBlock)("core/group", {
...restAttributes,
style: cleanEmptyObject({
...style,
spacing: {
...style?.spacing,
blockGap: "1em"
},
color: {
...style?.color,
duotone: void 0
}
}),
layout: {
type: "flex",
flexWrap: "nowrap",
verticalAlignment: "top"
}
}, [shouldInsertAvatarBlock && (0, _wordpress_blocks.createBlock)("core/avatar", {
size: avatarSize,
style: cleanEmptyObject({
border: { radius: "0px" },
color: { duotone: style?.color?.duotone }
})
}), (0, _wordpress_blocks.createBlock)("core/group", {
style: {
layout: {
selfStretch: "fill",
flexSize: null
},
spacing: { blockGap: "0" }
},
layout: {
type: "flex",
orientation: "vertical",
justifyContent: "stretch"
}
}, [
shouldInsertParagraphBlock && (0, _wordpress_blocks.createBlock)("core/paragraph", {
content: byline,
placeholder: (0, _wordpress_i18n.__)("Write byline…"),
style: { typography: {
fontSize: "0.5em",
textAlign
} }
}),
shouldInsertPostAuthorNameBlock && (0, _wordpress_blocks.createBlock)("core/post-author-name", {
isLink,
linkTarget,
style: { typography: {
fontSize: "1em",
textAlign
} }
}),
shouldInsertPostAuthorBiographyBlock && (0, _wordpress_blocks.createBlock)("core/post-author-biography", { style: { typography: {
fontSize: "0.7em",
textAlign
} } })
].filter(Boolean))].filter(Boolean));
}
exports.recreateWithRecommendedBlocks = recreateWithRecommendedBlocks;
//# sourceMappingURL=utils.cjs.map