@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
53 lines (50 loc) • 1.73 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = PostAuthorCheck;
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _postTypeSupportCheck = _interopRequireDefault(require("../post-type-support-check"));
var _store = require("../../store");
var _constants = require("./constants");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Wrapper component that renders its children only if the post type supports the author.
*
* @param {Object} props The component props.
* @param {Element} props.children Children to be rendered.
*
* @return {Component|null} The component to be rendered. Return `null` if the post type doesn't
* supports the author or if there are no authors available.
*/function PostAuthorCheck({
children
}) {
const {
hasAssignAuthorAction,
hasAuthors
} = (0, _data.useSelect)(select => {
var _post$_links$wpActio;
const post = select(_store.store).getCurrentPost();
const authors = select(_coreData.store).getUsers(_constants.AUTHORS_QUERY);
return {
hasAssignAuthorAction: (_post$_links$wpActio = post._links?.['wp:action-assign-author']) !== null && _post$_links$wpActio !== void 0 ? _post$_links$wpActio : false,
hasAuthors: authors?.length >= 1
};
}, []);
if (!hasAssignAuthorAction || !hasAuthors) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_postTypeSupportCheck.default, {
supportKeys: "author",
children: children
});
}
//# sourceMappingURL=check.js.map