/** * Retrieves the translation of text. * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/ */ import { __ } from '@wordpress/i18n'; /** * React hook that is used to mark the block wrapper element. * It provides all the necessary props like the class name. * * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops */ import { useBlockProps, InspectorControls, RichText } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; import { useEntityProp } from '@wordpress/core-data'; import { TextControl, DatePicker, TimePicker, PanelBody, PanelRow } from '@wordpress/components'; /** * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. * Those files can contain any CSS code that gets applied to the editor. * * @see https://www.npmjs.com/package/@wordpress/scripts#using-css */ import './editor.scss'; /** * The edit function describes the structure of your block in the context of the * editor. This represents what the editor will render when the block is used. * * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit * * @return {WPElement} Element to render. */ export default function Edit() { const blockProps = useBlockProps(); const postType = useSelect( ( select ) => select( 'core/editor' ).getCurrentPostType(), [] ); const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' ); const bookTitle = meta[ '_meta_fields_book_title' ]; const bookAuthor = meta[ '_meta_fields_book_author' ]; const bookPublisher = meta[ '_meta_fields_book_publisher' ]; const bookDate = meta[ '_meta_fields_book_date' ]; const updateBookTitleMetaValue = ( newValue ) => { setMeta( { ...meta, _meta_fields_book_title: newValue } ); }; const updateBookAuthorMetaValue = ( newValue ) => { setMeta( { ...meta, _meta_fields_book_author: newValue } ); }; const updateBookPublisherMetaValue = ( newValue ) => { setMeta( { ...meta, _meta_fields_book_publisher: newValue } ); }; return ( <>
setMeta( { ...meta, _meta_fields_book_date: newValue } ) } __nextRemoveHelpButton __nextRemoveResetButton />
{ /* https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/date-time https://developer.wordpress.org/block-editor/reference-guides/components/date-time/ */ } setMeta( { ...meta, _meta_fields_book_date: newValue } ) } __nextRemoveHelpButton __nextRemoveResetButton />
); }