import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { PanelBody, SelectControl, Placeholder } from '@wordpress/components'; import { useEntityProp } from '@wordpress/core-data'; import { useSelect } from '@wordpress/data'; import Fields from '../_meta/Fields'; const Edit = ({ attributes, setAttributes }) => { const { fieldName } = attributes; const { fields } = window.jvbFieldConfig || {}; const postType = useSelect( (select) => select('core/editor').getCurrentPostType(), [] ); const [meta, setMeta] = useEntityProp('postType', postType, 'meta'); const field = (fields || []).find((f) => f.name === fieldName); const blockProps = useBlockProps(); return (
({ label: f.label || f.name, value: f.name })), ]} onChange={(value) => setAttributes({ fieldName: value })} /> { !field && } { field && ( setMeta({ ...meta, [fieldName]: value })} meta={meta} /> ) }
); }; export default Edit;