UNPKG

@wordpress/block-library

Version:
76 lines (75 loc) • 3.15 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_components = require("@wordpress/components"); let _wordpress_core_data = require("@wordpress/core-data"); let _wordpress_data = require("@wordpress/data"); let _wordpress_i18n = require("@wordpress/i18n"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/comment-author-avatar/edit.jsx function Edit({ attributes, context: { commentId }, setAttributes, isSelected }) { const { height, width } = attributes; const [avatars] = (0, _wordpress_core_data.useEntityProp)("root", "comment", "author_avatar_urls", commentId); const [authorName] = (0, _wordpress_core_data.useEntityProp)("root", "comment", "author_name", commentId); const avatarUrls = avatars ? Object.values(avatars) : null; const sizes = avatars ? Object.keys(avatars) : null; const minSize = sizes ? sizes[0] : 24; const maxSize = sizes ? sizes[sizes.length - 1] : 96; const blockProps = (0, _wordpress_block_editor.useBlockProps)(); const spacingProps = (0, _wordpress_block_editor.__experimentalGetSpacingClassesAndStyles)(attributes); const maxSizeBuffer = Math.floor(maxSize * 2.5); const avatarURL = (0, _wordpress_data.useSelect)((select) => { const { __experimentalDiscussionSettings } = select(_wordpress_block_editor.store).getSettings(); return __experimentalDiscussionSettings?.avatarURL; }, []); const inspectorControls = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.PanelBody, { title: (0, _wordpress_i18n.__)("Settings"), children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.RangeControl, { label: (0, _wordpress_i18n.__)("Image size"), onChange: (newWidth) => setAttributes({ width: newWidth, height: newWidth }), min: minSize, max: maxSizeBuffer, initialPosition: width, value: width }) }) }); const resizableAvatar = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ResizableBox, { size: { width, height }, showHandle: isSelected, onResizeStop: (event, direction, elt, delta) => { setAttributes({ height: parseInt(height + delta.height, 10), width: parseInt(width + delta.width, 10) }); }, lockAspectRatio: true, enable: { top: false, right: !(0, _wordpress_i18n.isRTL)(), bottom: true, left: (0, _wordpress_i18n.isRTL)() }, minWidth: minSize, maxWidth: maxSizeBuffer, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", { src: avatarUrls ? avatarUrls[avatarUrls.length - 1] : avatarURL, alt: `${authorName} ${(0, _wordpress_i18n.__)("Avatar")}`, ...blockProps }) }); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [inspectorControls, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { ...spacingProps, children: resizableAvatar })] }); } exports.default = Edit; //# sourceMappingURL=edit.cjs.map