UNPKG

@wordpress/block-library

Version:
80 lines (79 loc) • 3.94 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_core_data = require("@wordpress/core-data"); let _wordpress_date = require("@wordpress/date"); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_components = require("@wordpress/components"); let _wordpress_i18n = require("@wordpress/i18n"); let ___utils_hooks_js = require("../utils/hooks.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/comment-date/edit.jsx /** * Renders the `core/comment-date` block on the editor. * * @param {Object} props React props. * @param {Object} props.setAttributes Callback for updating block attributes. * @param {Object} props.attributes Block attributes. * @param {string} props.attributes.format Format of the date. * @param {string} props.attributes.isLink Whether the author name should be linked. * @param {Object} props.context Inherited context. * @param {string} props.context.commentId The comment ID. * * @return {React.JSX.Element} React element. */ function Edit({ attributes: { format, isLink }, context: { commentId }, setAttributes }) { const blockProps = (0, _wordpress_block_editor.useBlockProps)(); const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)(); let [date] = (0, _wordpress_core_data.useEntityProp)("root", "comment", "date", commentId); const [siteFormat = (0, _wordpress_date.getSettings)().formats.date] = (0, _wordpress_core_data.useEntityProp)("root", "site", "date_format"); 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({ format: void 0, isLink: true }); }, dropdownMenuProps, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Date format"), hasValue: () => format !== void 0, onDeselect: () => setAttributes({ format: void 0 }), isShownByDefault: true, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.__experimentalDateFormatPicker, { format, defaultFormat: siteFormat, onChange: (nextFormat) => setAttributes({ format: nextFormat }) }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Link to comment"), hasValue: () => !isLink, onDeselect: () => setAttributes({ isLink: true }), isShownByDefault: true, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Link to comment"), onChange: () => setAttributes({ isLink: !isLink }), checked: isLink }) })] }) }); if (!commentId || !date) date = (0, _wordpress_i18n._x)("Comment Date", "block title"); let commentDate = date instanceof Date ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("time", { dateTime: (0, _wordpress_date.dateI18n)("c", date), children: format === "human-diff" ? (0, _wordpress_date.humanTimeDiff)(date) : (0, _wordpress_date.dateI18n)(format || siteFormat, date) }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("time", { children: date }); if (isLink) commentDate = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", { href: "#comment-date-pseudo-link", onClick: (event) => event.preventDefault(), children: commentDate }); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [inspectorControls, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...blockProps, children: commentDate })] }); } exports.default = Edit; //# sourceMappingURL=edit.cjs.map