UNPKG

@wordpress/block-library

Version:
121 lines (120 loc) • 6.31 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 _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_core_data = require("@wordpress/core-data"); let _wordpress_components = require("@wordpress/components"); let _wordpress_data = require("@wordpress/data"); let ___utils_hooks_js = require("../utils/hooks.cjs"); let ___utils_deprecated_text_align_attributes_js = require("../utils/deprecated-text-align-attributes.cjs"); ___utils_deprecated_text_align_attributes_js = __toESM(___utils_deprecated_text_align_attributes_js); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/comments-title/edit.jsx function Edit(props) { (0, ___utils_deprecated_text_align_attributes_js.default)(props); const { attributes, setAttributes, context } = props; const { showPostTitle, showCommentsCount, level = 2, levelOptions } = attributes; const { postId, postType } = context; const TagName = "h" + level; const [rawTitle] = (0, _wordpress_core_data.useEntityProp)("postType", postType, "title", postId); const isSiteEditor = typeof postId === "undefined"; const blockProps = (0, _wordpress_block_editor.useBlockProps)(); const { threadCommentsDepth, threadComments, commentsPerPage, pageComments } = (0, _wordpress_data.useSelect)((select) => { const { getSettings } = select(_wordpress_block_editor.store); return getSettings().__experimentalDiscussionSettings ?? {}; }, []); const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)(); const { totalItems, hasResolved } = (0, ___utils_hooks_js.usePostCommentsCount)(postId); let commentsCount; if (isSiteEditor) { const nestedCommentsNumber = threadComments ? Math.min(threadCommentsDepth, 3) - 1 : 0; const commentsNumber = parseInt(nestedCommentsNumber) + parseInt(pageComments ? commentsPerPage : 3); commentsCount = Math.min(commentsNumber, 3); } else commentsCount = totalItems ?? (hasResolved ? 0 : void 0); const blockControls = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, { group: "block", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.HeadingLevelDropdown, { value: level, options: levelOptions, onChange: (newLevel) => setAttributes({ level: newLevel }) }) }); const inspectorControls = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalToolsPanel, { label: (0, _wordpress_i18n.__)("Settings"), resetAll: () => { setAttributes({ showPostTitle: true, showCommentsCount: true }); }, dropdownMenuProps, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Show post title"), isShownByDefault: true, hasValue: () => !showPostTitle, onDeselect: () => setAttributes({ showPostTitle: true }), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Show post title"), checked: showPostTitle, onChange: (value) => setAttributes({ showPostTitle: value }) }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Show comments count"), isShownByDefault: true, hasValue: () => !showCommentsCount, onDeselect: () => setAttributes({ showCommentsCount: true }), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Show comments count"), checked: showCommentsCount, onChange: (value) => setAttributes({ showCommentsCount: value }) }) })] }) }); const postTitle = isSiteEditor ? (0, _wordpress_i18n.__)("Post Title") : rawTitle; let placeholder; if (showCommentsCount && commentsCount !== void 0) { if (showPostTitle) { if (commentsCount === 1) placeholder = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("One response to \"%s\""), postTitle); else placeholder = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n._n)("%1$s response to \"%2$s\"", "%1$s responses to \"%2$s\"", commentsCount), commentsCount, postTitle); } else if (commentsCount === 1) placeholder = (0, _wordpress_i18n.__)("One response"); else placeholder = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n._n)("%s response", "%s responses", commentsCount), commentsCount); } else if (showPostTitle) { if (commentsCount === 1) placeholder = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Response to \"%s\""), postTitle); else placeholder = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Responses to \"%s\""), postTitle); } else if (commentsCount === 1) placeholder = (0, _wordpress_i18n.__)("Response"); else placeholder = (0, _wordpress_i18n.__)("Responses"); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [ blockControls, inspectorControls, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TagName, { ...blockProps, children: placeholder }) ] }); } exports.default = Edit; //# sourceMappingURL=edit.cjs.map