@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
48 lines (44 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PageAttributesCheck = PageAttributesCheck;
exports.default = void 0;
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _store = require("../../store");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Wrapper component that renders its children only if the post type supports page attributes.
*
* @param {Object} props - The component props.
* @param {Element} props.children - The child components to render.
*
* @return {Component|null} The rendered child components or null if page attributes are not supported.
*/
function PageAttributesCheck({
children
}) {
const supportsPageAttributes = (0, _data.useSelect)(select => {
const {
getEditedPostAttribute
} = select(_store.store);
const {
getPostType
} = select(_coreData.store);
const postType = getPostType(getEditedPostAttribute('type'));
return !!postType?.supports?.['page-attributes'];
}, []);
// Only render fields if post type supports page attributes or available templates exist.
if (!supportsPageAttributes) {
return null;
}
return children;
}
var _default = exports.default = PageAttributesCheck;
//# sourceMappingURL=check.js.map