-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Introduce the Editor component and use it in the site editor
- Loading branch information
1 parent
55dbce1
commit 70e5e79
Showing
4 changed files
with
178 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/edit-site/src/components/editor/use-editor-title.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useEditedEntityRecord from '../use-edited-entity-record'; | ||
import useTitle from '../routes/use-title'; | ||
import { POST_TYPE_LABELS, TEMPLATE_POST_TYPE } from '../../utils/constants'; | ||
|
||
function useEditorTitle() { | ||
const { | ||
record: editedPost, | ||
getTitle, | ||
isLoaded: hasLoadedPost, | ||
} = useEditedEntityRecord(); | ||
let title; | ||
if ( hasLoadedPost ) { | ||
title = sprintf( | ||
// translators: A breadcrumb trail for the Admin document title. %1$s: title of template being edited, %2$s: type of template (Template or Template Part). | ||
__( '%1$s ‹ %2$s' ), | ||
getTitle(), | ||
POST_TYPE_LABELS[ editedPost.type ] ?? | ||
POST_TYPE_LABELS[ TEMPLATE_POST_TYPE ] | ||
); | ||
} | ||
|
||
// Only announce the title once the editor is ready to prevent "Replace" | ||
// action in <URLQueryController> from double-announcing. | ||
useTitle( hasLoadedPost && title ); | ||
} | ||
|
||
export default useEditorTitle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* 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 EditorProvider from '../provider'; | ||
import Sidebar from '../sidebar'; | ||
|
||
function Editor( { | ||
postType, | ||
postId, | ||
templateId, | ||
settings, | ||
children, | ||
|
||
// 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. | ||
className, | ||
styles, | ||
customSaveButton, | ||
forceDisableBlockTools, | ||
title, | ||
iframeProps, | ||
extraSidebarPanels, | ||
enableRegionNavigation = true, | ||
} ) { | ||
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 ( | ||
<EditorProvider | ||
post={ post } | ||
__unstableTemplate={ template } | ||
settings={ settings } | ||
useSubRegistry={ false } | ||
> | ||
{ hasLoadedPost && ! post && ( | ||
<Notice status="warning" isDismissible={ false }> | ||
{ __( | ||
"You attempted to edit an item that doesn't exist. Perhaps it was deleted?" | ||
) } | ||
</Notice> | ||
) } | ||
<EditorInterface | ||
className={ className } | ||
styles={ styles } | ||
enableRegionNavigation={ enableRegionNavigation } | ||
customSaveButton={ customSaveButton } | ||
forceDisableBlockTools={ forceDisableBlockTools } | ||
title={ title } | ||
iframeProps={ iframeProps } | ||
/> | ||
<Sidebar | ||
onActionPerformed={ onActionPerformed } | ||
extraPanels={ extraSidebarPanels } | ||
/> | ||
{ children } | ||
</EditorProvider> | ||
); | ||
} | ||
|
||
export default Editor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters