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

Codify editor focus mode concept #56827

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 10 additions & 7 deletions packages/edit-site/src/components/block-editor/back-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ import { Button } from '@wordpress/components';
import { arrowLeft } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import {
TEMPLATE_PART_POST_TYPE,
NAVIGATION_POST_TYPE,
} from '../../utils/constants';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';

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

function BackButton() {
const location = useLocation();
const history = useHistory();
const isTemplatePart = location.params.postType === TEMPLATE_PART_POST_TYPE;
const isNavigationMenu = location.params.postType === NAVIGATION_POST_TYPE;

const previousTemplateId = location.state?.fromTemplateId;

const isFocusMode = isTemplatePart || isNavigationMenu;
const { isFocusMode } = useSelect( ( select ) => {
const { isEntityFocusMode } = unlock( select( editSiteStore ) );

return {
isFocusMode: isEntityFocusMode(),
};
}, [] );

if ( ! isFocusMode || ! previousTemplateId ) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import { privateApis as editorPrivateApis } from '@wordpress/editor';
*/
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';
import {
FOCUSABLE_ENTITIES,
NAVIGATION_POST_TYPE,
} from '../../utils/constants';
import { NAVIGATION_POST_TYPE } from '../../utils/constants';

const { ExperimentalBlockCanvas: BlockCanvas } = unlock(
blockEditorPrivateApis
Expand Down Expand Up @@ -53,12 +50,13 @@ function EditorCanvas( {
getEditedPostType,
__experimentalGetPreviewDeviceType,
getCanvasMode,
isEntityFocusMode,
} = unlock( select( editSiteStore ) );
const _templateType = getEditedPostType();

return {
templateType: _templateType,
isFocusMode: FOCUSABLE_ENTITIES.includes( _templateType ),
isFocusMode: isEntityFocusMode(),
deviceType: __experimentalGetPreviewDeviceType(),
isZoomOutMode: __unstableGetEditorMode() === 'zoom-out',
canvasMode: getCanvasMode(),
Expand Down Expand Up @@ -93,6 +91,7 @@ function EditorCanvas( {
};
const isTemplateTypeNavigation = templateType === NAVIGATION_POST_TYPE;
const isNavigationFocusMode = isTemplateTypeNavigation && isFocusMode;

// Hide the appender when:
// - In navigation focus mode (should only allow the root Nav block).
// - In view mode (i.e. not editing).
Expand Down
8 changes: 4 additions & 4 deletions packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ import {
useHasEditorCanvasContainer,
} from '../editor-canvas-container';
import { unlock } from '../../lock-unlock';
import { FOCUSABLE_ENTITIES } from '../../utils/constants';

const { BlockContextualToolbar } = unlock( blockEditorPrivateApis );

export default function HeaderEditMode( { setListViewToggleElement } ) {
const {
deviceType,
templateType,
isDistractionFree,
blockEditorMode,
blockSelectionStart,
Expand All @@ -57,12 +55,15 @@ export default function HeaderEditMode( { setListViewToggleElement } ) {
editorCanvasView,
hasFixedToolbar,
isZoomOutMode,
isFocusMode,
} = useSelect( ( select ) => {
const { __experimentalGetPreviewDeviceType, getEditedPostType } =
select( editSiteStore );
const { getBlockSelectionStart, __unstableGetEditorMode } =
select( blockEditorStore );

const { isEntityFocusMode } = unlock( select( editSiteStore ) );

const postType = getEditedPostType();

const {
Expand Down Expand Up @@ -93,6 +94,7 @@ export default function HeaderEditMode( { setListViewToggleElement } ) {
'distractionFree'
),
isZoomOutMode: __unstableGetEditorMode() === 'zoom-out',
isFocusMode: isEntityFocusMode(),
};
}, [] );

Expand All @@ -106,8 +108,6 @@ export default function HeaderEditMode( { setListViewToggleElement } ) {

const hasDefaultEditorCanvasView = ! useHasEditorCanvasContainer();

const isFocusMode = FOCUSABLE_ENTITIES.includes( templateType );

const isZoomedOutView = blockEditorMode === 'zoom-out';

const [ isBlockToolsCollapsed, setIsBlockToolsCollapsed ] =
Expand Down
12 changes: 12 additions & 0 deletions packages/edit-site/src/store/private-selectors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Internal dependencies
*/
import { FOCUSABLE_ENTITIES } from '../utils/constants';

import { getEditedPostType } from './selectors';

/**
* Returns the current canvas mode.
*
Expand All @@ -19,3 +26,8 @@ export function getCanvasMode( state ) {
export function getEditorCanvasContainerView( state ) {
return state.editorCanvasContainerView;
}

export function isEntityFocusMode( state ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isEntityFocusMode sounds a big confusing to me. Why not name it like what it does, checking focusable entities, so more like isEntityFocusable?

const postType = getEditedPostType( state );
return FOCUSABLE_ENTITIES.includes( postType );
}
Loading