UNPKG

@wordpress/editor

Version:
89 lines (82 loc) 2.04 kB
/** * WordPress dependencies */ import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { Notice } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import { TEMPLATE_POST_TYPE } from '../../store/constants'; import EditorInterface from '../editor-interface'; import { ExperimentalEditorProvider } from '../provider'; import Sidebar from '../sidebar'; function Editor( { postType, postId, templateId, settings, children, initialEdits, // This could be part of the settings. onActionPerformed, // The following abstractions are not ideal but necessary // to account for site editor and post editor differences for now. extraContent, extraSidebarPanels, ...props } ) { const { post, template, hasLoadedPost } = useSelect( ( select ) => { const { getEntityRecord, hasFinishedResolution } = select( coreStore ); return { post: getEntityRecord( 'postType', postType, postId ), template: templateId ? getEntityRecord( 'postType', TEMPLATE_POST_TYPE, templateId ) : undefined, hasLoadedPost: hasFinishedResolution( 'getEntityRecord', [ 'postType', postType, postId, ] ), }; }, [ postType, postId, templateId ] ); return ( <> { hasLoadedPost && ! post && ( <Notice status="warning" isDismissible={ false }> { __( "You attempted to edit an item that doesn't exist. Perhaps it was deleted?" ) } </Notice> ) } { !! post && ( <ExperimentalEditorProvider post={ post } __unstableTemplate={ template } settings={ settings } initialEdits={ initialEdits } useSubRegistry={ false } > <EditorInterface { ...props }> { extraContent } </EditorInterface> { children } <Sidebar onActionPerformed={ onActionPerformed } extraPanels={ extraSidebarPanels } /> </ExperimentalEditorProvider> ) } </> ); } export default Editor;