UNPKG

@wordpress/block-library

Version:
113 lines (110 loc) 3.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = Edit; var _coreData = require("@wordpress/core-data"); var _date = require("@wordpress/date"); var _blockEditor = require("@wordpress/block-editor"); var _components = require("@wordpress/components"); var _i18n = require("@wordpress/i18n"); var _hooks = require("../utils/hooks"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * 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 {JSX.Element} React element. */function Edit({ attributes: { format, isLink }, context: { commentId }, setAttributes }) { const blockProps = (0, _blockEditor.useBlockProps)(); const dropdownMenuProps = (0, _hooks.useToolsPanelDropdownMenuProps)(); let [date] = (0, _coreData.useEntityProp)('root', 'comment', 'date', commentId); const [siteFormat = (0, _date.getSettings)().formats.date] = (0, _coreData.useEntityProp)('root', 'site', 'date_format'); const inspectorControls = /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, { children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalToolsPanel, { label: (0, _i18n.__)('Settings'), resetAll: () => { setAttributes({ format: undefined, isLink: true }); }, dropdownMenuProps: dropdownMenuProps, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanelItem, { label: (0, _i18n.__)('Date format'), hasValue: () => format !== undefined, onDeselect: () => setAttributes({ format: undefined }), isShownByDefault: true, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.__experimentalDateFormatPicker, { format: format, defaultFormat: siteFormat, onChange: nextFormat => setAttributes({ format: nextFormat }) }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanelItem, { label: (0, _i18n.__)('Link to comment'), hasValue: () => !isLink, onDeselect: () => setAttributes({ isLink: true }), isShownByDefault: true, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToggleControl, { __nextHasNoMarginBottom: true, label: (0, _i18n.__)('Link to comment'), onChange: () => setAttributes({ isLink: !isLink }), checked: isLink }) })] }) }); if (!commentId || !date) { date = (0, _i18n._x)('Comment Date', 'block title'); } let commentDate = date instanceof Date ? /*#__PURE__*/(0, _jsxRuntime.jsx)("time", { dateTime: (0, _date.dateI18n)('c', date), children: format === 'human-diff' ? (0, _date.humanTimeDiff)(date) : (0, _date.dateI18n)(format || siteFormat, date) }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("time", { children: date }); if (isLink) { commentDate = /*#__PURE__*/(0, _jsxRuntime.jsx)("a", { href: "#comment-date-pseudo-link", onClick: event => event.preventDefault(), children: commentDate }); } return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [inspectorControls, /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { ...blockProps, children: commentDate })] }); } //# sourceMappingURL=edit.js.map