Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Editor: Use the same editor component for all routes #69093

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';
import { decodeEntities } from '@wordpress/html-entities';
import { Icon, arrowUpLeft } from '@wordpress/icons';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { addQueryArgs } from '@wordpress/url';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the incorrect position of the import statement.


/**
* Internal dependencies
Expand Down Expand Up @@ -53,7 +54,7 @@ import {
useResolveEditedEntity,
useSyncDeprecatedEntityIntoState,
} from './use-resolve-edited-entity';
import { addQueryArgs } from '@wordpress/url';
import SitePreview from './site-preview';

const { Editor, BackButton } = unlock( editorPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );
Expand Down Expand Up @@ -117,7 +118,10 @@ function getNavigationPath( location, postType ) {
return addQueryArgs( path, { canvas: undefined } );
}

export default function EditSiteEditor( { isPostsList = false } ) {
export default function EditSiteEditor( {
isHomeRoute = false,
isPostsList = false,
} ) {
const disableMotion = useReducedMotion();
const location = useLocation();
const { canvas = 'view' } = location.query;
Expand All @@ -128,7 +132,7 @@ export default function EditSiteEditor( { isPostsList = false } ) {
useSyncDeprecatedEntityIntoState( entity );
const { postType, postId, context } = entity;
const {
supportsGlobalStyles,
isBlockBasedTheme,
editorCanvasView,
currentPostIsTrashed,
hasSiteIcon,
Expand All @@ -140,7 +144,7 @@ export default function EditSiteEditor( { isPostsList = false } ) {
const siteData = getEntityRecord( 'root', '__unstableBase', undefined );

return {
supportsGlobalStyles: getCurrentTheme()?.is_block_theme,
isBlockBasedTheme: getCurrentTheme()?.is_block_theme,
editorCanvasView: getEditorCanvasContainerView(),
currentPostIsTrashed:
select( editorStore ).getCurrentPostAttribute( 'status' ) ===
Expand Down Expand Up @@ -244,7 +248,9 @@ export default function EditSiteEditor( { isPostsList = false } ) {
duration: disableMotion ? 0 : 0.2,
};

return (
return ! isBlockBasedTheme && isHomeRoute ? (
<SitePreview />
) : (
<>
<GlobalStylesRenderer
disableRootPadding={ postType !== TEMPLATE_POST_TYPE }
Expand Down Expand Up @@ -349,7 +355,7 @@ export default function EditSiteEditor( { isPostsList = false } ) {
</BackButton>
) }
<SiteEditorMoreMenu />
{ supportsGlobalStyles && <GlobalStylesSidebar /> }
{ isBlockBasedTheme && <GlobalStylesSidebar /> }
</Editor>
) }
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
/**
* WordPress dependencies
*/

import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/

import Editor from '../editor';

export function MaybeEditor( { showEditor = true } ) {
const { isBlockBasedTheme, siteUrl } = useSelect( ( select ) => {
const { getEntityRecord, getCurrentTheme } = select( coreStore );
export default function SitePreview() {
const siteUrl = useSelect( ( select ) => {
const { getEntityRecord } = select( coreStore );
const siteData = getEntityRecord( 'root', '__unstableBase' );

return {
isBlockBasedTheme: getCurrentTheme()?.is_block_theme,
siteUrl: siteData?.home,
};
return siteData?.home;
}, [] );

// If theme is block based, return the Editor, otherwise return the site preview.
return isBlockBasedTheme || showEditor ? (
<Editor />
) : (
return (
<iframe
src={ siteUrl }
title={ __( 'Site Preview' ) }
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/site-editor-routes/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* Internal dependencies
*/
import SidebarNavigationScreenMain from '../sidebar-navigation-screen-main';
import { MaybeEditor } from '../maybe-editor';
import Editor from '../editor';

export const homeRoute = {
name: 'home',
path: '/',
areas: {
sidebar: <SidebarNavigationScreenMain />,
preview: <MaybeEditor showEditor={ false } />,
preview: <Editor isHomeRoute />,
mobile: <SidebarNavigationScreenMain />,
},
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* Internal dependencies
*/
import { MaybeEditor } from '../maybe-editor';
import Editor from '../editor';
import SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';

export const templateItemRoute = {
name: 'template-item',
path: '/wp_template/*postId',
areas: {
sidebar: <SidebarNavigationScreenTemplatesBrowse backPath="/" />,
mobile: <MaybeEditor />,
preview: <MaybeEditor />,
mobile: <Editor />,
preview: <Editor />,
},
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* Internal dependencies
*/
import { MaybeEditor } from '../maybe-editor';
import Editor from '../editor';
import SidebarNavigationScreenPatterns from '../sidebar-navigation-screen-patterns';

export const templatePartItemRoute = {
name: 'template-part-item',
path: '/wp_template_part/*postId',
areas: {
sidebar: <SidebarNavigationScreenPatterns backPath="/" />,
mobile: <MaybeEditor />,
preview: <MaybeEditor />,
mobile: <Editor />,
preview: <Editor />,
},
};
Loading