UNPKG

@wordpress/block-library

Version:
131 lines (127 loc) 4.48 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _clsx = _interopRequireDefault(require("clsx")); var _blockEditor = require("@wordpress/block-editor"); var _data = require("@wordpress/data"); var _i18n = require("@wordpress/i18n"); var _coreData = require("@wordpress/core-data"); var _components = require("@wordpress/components"); var _hooks = require("../utils/hooks"); var _jsxRuntime = require("react/jsx-runtime"); /** * External dependencies */ /** * WordPress dependencies */ /** * Internal dependencies */ function PostAuthorNameEdit({ context: { postType, postId }, attributes: { textAlign, isLink, linkTarget }, setAttributes }) { const { authorName, supportsAuthor } = (0, _data.useSelect)(select => { var _getPostType$supports; const { getEditedEntityRecord, getUser, getPostType } = select(_coreData.store); const _authorId = getEditedEntityRecord('postType', postType, postId)?.author; return { authorName: _authorId ? getUser(_authorId) : null, supportsAuthor: (_getPostType$supports = getPostType(postType)?.supports?.author) !== null && _getPostType$supports !== void 0 ? _getPostType$supports : false }; }, [postType, postId]); const blockProps = (0, _blockEditor.useBlockProps)({ className: (0, _clsx.default)({ [`has-text-align-${textAlign}`]: textAlign }) }); const displayName = authorName?.name || (0, _i18n.__)('Author Name'); const displayAuthor = isLink ? /*#__PURE__*/(0, _jsxRuntime.jsx)("a", { href: "#author-pseudo-link", onClick: event => event.preventDefault(), className: "wp-block-post-author-name__link", children: displayName }) : displayName; const dropdownMenuProps = (0, _hooks.useToolsPanelDropdownMenuProps)(); return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockControls, { group: "block", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.AlignmentControl, { value: textAlign, onChange: nextAlign => { setAttributes({ textAlign: nextAlign }); } }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, { children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalToolsPanel, { label: (0, _i18n.__)('Settings'), resetAll: () => { setAttributes({ isLink: false, linkTarget: '_self' }); }, dropdownMenuProps: dropdownMenuProps, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanelItem, { label: (0, _i18n.__)('Link to author archive'), isShownByDefault: true, hasValue: () => isLink, onDeselect: () => setAttributes({ isLink: false }), children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToggleControl, { __nextHasNoMarginBottom: true, label: (0, _i18n.__)('Link to author archive'), onChange: () => setAttributes({ isLink: !isLink }), checked: isLink }) }), isLink && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanelItem, { label: (0, _i18n.__)('Open in new tab'), isShownByDefault: true, hasValue: () => linkTarget !== '_self', onDeselect: () => setAttributes({ linkTarget: '_self' }), children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToggleControl, { __nextHasNoMarginBottom: true, label: (0, _i18n.__)('Open in new tab'), onChange: value => setAttributes({ linkTarget: value ? '_blank' : '_self' }), checked: linkTarget === '_blank' }) })] }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { ...blockProps, children: !supportsAuthor && postType !== undefined ? (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "post". (0, _i18n.__)('This post type (%s) does not support the author.'), postType) : displayAuthor })] }); } var _default = exports.default = PostAuthorNameEdit; //# sourceMappingURL=edit.js.map