@wordpress/block-library
Version:
Block library for the WordPress editor.
61 lines (60 loc) • 1.66 kB
JavaScript
// packages/block-library/src/post-author-biography/edit.js
import clsx from "clsx";
import {
AlignmentControl,
BlockControls,
useBlockProps
} from "@wordpress/block-editor";
import { useSelect } from "@wordpress/data";
import { __ } from "@wordpress/i18n";
import { store as coreStore } from "@wordpress/core-data";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
function PostAuthorBiographyEdit({
context: { postType, postId },
attributes: { textAlign },
setAttributes
}) {
const { authorDetails } = useSelect(
(select) => {
const { getEditedEntityRecord, getUser } = select(coreStore);
const _authorId = getEditedEntityRecord(
"postType",
postType,
postId
)?.author;
return {
authorDetails: _authorId ? getUser(_authorId) : null
};
},
[postType, postId]
);
const blockProps = useBlockProps({
className: clsx({
[`has-text-align-${textAlign}`]: textAlign
})
});
const displayAuthorBiography = authorDetails?.description || __("Author Biography");
return /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(BlockControls, { group: "block", children: /* @__PURE__ */ jsx(
AlignmentControl,
{
value: textAlign,
onChange: (nextAlign) => {
setAttributes({ textAlign: nextAlign });
}
}
) }),
/* @__PURE__ */ jsx(
"div",
{
...blockProps,
dangerouslySetInnerHTML: { __html: displayAuthorBiography }
}
)
] });
}
var edit_default = PostAuthorBiographyEdit;
export {
edit_default as default
};
//# sourceMappingURL=edit.js.map