UNPKG

@wordpress/block-library

Version:
95 lines (94 loc) • 4.91 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); let clsx = require("clsx"); clsx = __toESM(clsx); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_components = require("@wordpress/components"); let _wordpress_compose = require("@wordpress/compose"); let _wordpress_core_data = require("@wordpress/core-data"); let _wordpress_data = require("@wordpress/data"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/post-comments-form/form.jsx const CommentsFormPlaceholder = () => { const instanceId = (0, _wordpress_compose.useInstanceId)(CommentsFormPlaceholder); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { className: "comment-respond", children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { className: "comment-reply-title", children: (0, _wordpress_i18n.__)("Leave a Reply") }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", { noValidate: true, className: "comment-form", onSubmit: (event) => event.preventDefault(), children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", { htmlFor: `comment-${instanceId}`, children: (0, _wordpress_i18n.__)("Comment") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", { id: `comment-${instanceId}`, name: "comment", cols: "45", rows: "8", readOnly: true })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { className: "form-submit wp-block-button", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { name: "submit", type: "submit", className: (0, clsx.default)("wp-block-button__link", (0, _wordpress_block_editor.__experimentalGetElementClassName)("button")), label: (0, _wordpress_i18n.__)("Post Comment"), value: (0, _wordpress_i18n.__)("Post Comment"), "aria-disabled": "true" }) })] })] }); }; const CommentsForm = ({ postId, postType }) => { const [commentStatus, setCommentStatus] = (0, _wordpress_core_data.useEntityProp)("postType", postType, "comment_status", postId); const isSiteEditor = postType === void 0 || postId === void 0; const defaultCommentStatus = (0, _wordpress_data.useSelect)((select) => select(_wordpress_block_editor.store).getSettings().__experimentalDiscussionSettings?.defaultCommentStatus, []); const postTypeSupportsComments = (0, _wordpress_data.useSelect)((select) => postType ? !!select(_wordpress_core_data.store).getPostType(postType)?.supports.comments : false); if (!isSiteEditor && "open" !== commentStatus) { if ("closed" === commentStatus) { const actions = [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, { __next40pxDefaultSize: true, onClick: () => setCommentStatus("open"), variant: "primary", children: (0, _wordpress_i18n._x)("Enable comments", "action that affects the current post") }, "enableComments")]; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.Warning, { actions, children: (0, _wordpress_i18n.__)("Post Comments Form block: Comments are not enabled for this item.") }); } else if (!postTypeSupportsComments) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.Warning, { children: (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Post Comments Form block: Comments are not enabled for this post type (%s)."), postType) }); else if ("open" !== defaultCommentStatus) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.Warning, { children: (0, _wordpress_i18n.__)("Post Comments Form block: Comments are not enabled.") }); } return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CommentsFormPlaceholder, {}); }; exports.default = CommentsForm; //# sourceMappingURL=form.cjs.map