Skip to content

Commit

Permalink
Handle click on the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Mar 21, 2024
1 parent d818111 commit 10edde3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
16 changes: 14 additions & 2 deletions packages/edit-site/src/components/block-editor/editor-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import { computeIFrameScale } from '../../utils/math';

const { EditorCanvas: EditorCanvasRoot } = unlock( editorPrivateApis );

function EditorCanvas( { enableResizing, settings, children, ...props } ) {
function EditorCanvas( {
enableResizing,
settings,
children,
onClick,
...props
} ) {
const { hasBlocks, isFocusMode, templateType, canvasMode, isZoomOutMode } =
useSelect( ( select ) => {
const { getBlockCount, __unstableGetEditorMode } =
Expand Down Expand Up @@ -69,7 +75,13 @@ function EditorCanvas( { enableResizing, settings, children, ...props } ) {
setCanvasMode( 'edit' );
}
},
onClick: () => setCanvasMode( 'edit' ),
onClick: () => {
if ( !! onClick ) {
onClick();
} else {
setCanvasMode( 'edit' );
}
},
readonly: true,
};
const isTemplateTypeNavigation = templateType === NAVIGATION_POST_TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';

const { useLocation } = unlock( routerPrivateApis );

export default function SiteEditorCanvas() {
export default function SiteEditorCanvas( { onClick } ) {
const location = useLocation();
const { templateType, isFocusableEntity, isViewMode } = useSelect(
( select ) => {
Expand Down Expand Up @@ -87,6 +87,7 @@ export default function SiteEditorCanvas() {
<EditorCanvas
enableResizing={ enableResizing }
settings={ settings }
onClick={ onClick }
>
{ resizeObserver }
</EditorCanvas>
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const interfaceLabels = {
footer: __( 'Editor footer' ),
};

export default function Editor( { isLoading } ) {
export default function Editor( { isLoading, onClick } ) {
const {
record: editedPost,
getTitle,
Expand Down Expand Up @@ -225,7 +225,7 @@ export default function Editor( { isLoading } ) {
{ ! isLargeViewport && (
<BlockToolbar hideDragHandle />
) }
<SiteEditorCanvas />
<SiteEditorCanvas onClick={ onClick } />
<PatternModal />
</>
) }
Expand Down
15 changes: 13 additions & 2 deletions packages/edit-site/src/components/layout/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import {
TEMPLATE_PART_POST_TYPE,
} from '../../utils/constants';

const { useLocation } = unlock( routerPrivateApis );
const { useLocation, useHistory } = unlock( routerPrivateApis );

export default function useLayoutAreas() {
const isSiteEditorLoading = useIsSiteEditorLoading();
const history = useHistory();
const { params } = useLocation();
const { postType, postId, path, layout, isCustom, canvas } = params ?? {};

Expand All @@ -35,7 +36,17 @@ export default function useLayoutAreas() {
areas: {
content: <PagePages />,
preview: isListLayout && (
<Editor isLoading={ isSiteEditorLoading } />
<Editor
isLoading={ isSiteEditorLoading }
onClick={ () =>
history.push( {
path,
postType: 'page',
postId,
canvas: 'edit',
} )
}
/>
),
mobile:
canvas === 'edit' ? (
Expand Down

0 comments on commit 10edde3

Please sign in to comment.