@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
60 lines (49 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ThemeSupportCheck = ThemeSupportCheck;
exports.default = void 0;
var _lodash = require("lodash");
var _data = require("@wordpress/data");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
function ThemeSupportCheck({
themeSupports,
children,
postType,
supportKeys
}) {
const isSupported = (0, _lodash.some)((0, _lodash.castArray)(supportKeys), key => {
const supported = (0, _lodash.get)(themeSupports, [key], false); // 'post-thumbnails' can be boolean or an array of post types.
// In the latter case, we need to verify `postType` exists
// within `supported`. If `postType` isn't passed, then the check
// should fail.
if ('post-thumbnails' === key && (0, _lodash.isArray)(supported)) {
return (0, _lodash.includes)(supported, postType);
}
return supported;
});
if (!isSupported) {
return null;
}
return children;
}
var _default = (0, _data.withSelect)(select => {
const {
getThemeSupports
} = select('core');
const {
getEditedPostAttribute
} = select('core/editor');
return {
postType: getEditedPostAttribute('type'),
themeSupports: getThemeSupports()
};
})(ThemeSupportCheck);
exports.default = _default;
//# sourceMappingURL=index.js.map