UNPKG

@wordpress/edit-post

Version:
58 lines (53 loc) 1.54 kB
import { createElement } from "@wordpress/element"; /** * External dependencies */ import { filter, map } from 'lodash'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { withSelect } from '@wordpress/data'; /** * Internal dependencies */ import Section from './section'; import { EnableCustomFieldsOption, EnablePanelOption } from './options'; import { store as editPostStore } from '../../store'; export function MetaBoxesSection({ areCustomFieldsRegistered, metaBoxes, ...sectionProps }) { // The 'Custom Fields' meta box is a special case that we handle separately. const thirdPartyMetaBoxes = filter(metaBoxes, ({ id }) => id !== 'postcustom'); if (!areCustomFieldsRegistered && thirdPartyMetaBoxes.length === 0) { return null; } return createElement(Section, sectionProps, areCustomFieldsRegistered && createElement(EnableCustomFieldsOption, { label: __('Custom fields') }), map(thirdPartyMetaBoxes, ({ id, title }) => createElement(EnablePanelOption, { key: id, label: title, panelName: `meta-box-${id}` }))); } export default withSelect(select => { const { getEditorSettings } = select('core/editor'); const { getAllMetaBoxes } = select(editPostStore); return { // This setting should not live in the block editor's store. areCustomFieldsRegistered: getEditorSettings().enableCustomFields !== undefined, metaBoxes: getAllMetaBoxes() }; })(MetaBoxesSection); //# sourceMappingURL=meta-boxes-section.js.map