@wordpress/block-library
Version:
Block library for the WordPress editor.
39 lines (38 loc) • 1.84 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_data = require("@wordpress/data");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_core_data = require("@wordpress/core-data");
let ___utils_hooks_js = require("../utils/hooks.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/post-comments-link/edit.jsx
function PostCommentsLinkEdit({ context }) {
const { postType, postId } = context;
const { totalItems: commentsCount } = (0, ___utils_hooks_js.usePostCommentsCount)(postId);
const blockProps = (0, _wordpress_block_editor.useBlockProps)();
const post = (0, _wordpress_data.useSelect)((select) => select(_wordpress_core_data.store).getEditedEntityRecord("postType", postType, postId), [postType, postId]);
let commentsText;
if (commentsCount !== null) {
const commentsNumber = parseInt(commentsCount);
if (commentsNumber === 0) commentsText = (0, _wordpress_i18n.__)("No comments");
else commentsText = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n._n)("%s comment", "%s comments", commentsNumber), commentsNumber.toLocaleString());
}
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
...blockProps,
children: post?.link && commentsText !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
href: post?.link + "#comments",
onClick: (event) => event.preventDefault(),
children: commentsText
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
href: "#post-comments-link-pseudo-link",
onClick: (event) => event.preventDefault(),
children: (0, _wordpress_i18n.__)("No comments")
})
});
}
exports.default = PostCommentsLinkEdit;
//# sourceMappingURL=edit.cjs.map