-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Only enter the zoom-out mode when not in the focus mode #56885
Merged
talldan
merged 1 commit into
try/zoomed-out-mode-experiments
from
fix/not-enter-zoom-out-in-focus-mode
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -3,19 +3,28 @@ | |
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { Button, VisuallyHidden } from '@wordpress/components'; | ||
import { __experimentalLibrary as Library } from '@wordpress/block-editor'; | ||
import { | ||
__experimentalLibrary as Library, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { close } from '@wordpress/icons'; | ||
import { | ||
useViewportMatch, | ||
__experimentalUseDialog as useDialog, | ||
} from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useEffect, useRef } from '@wordpress/element'; | ||
import { useEffect, useRef, useCallback } from '@wordpress/element'; | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../store'; | ||
import { useHasEditorCanvasContainer } from '../editor-canvas-container'; | ||
import { FOCUSABLE_ENTITIES } from '../../utils/constants'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { useLocation } = unlock( routerPrivateApis ); | ||
|
||
export default function InserterSidebar() { | ||
const { closeGeneralSidebar, setIsInserterOpened } = | ||
|
@@ -24,6 +33,17 @@ export default function InserterSidebar() { | |
( select ) => select( editSiteStore ).__experimentalGetInsertionPoint(), | ||
[] | ||
); | ||
const isFocusMode = useSelect( ( select ) => | ||
FOCUSABLE_ENTITIES.includes( | ||
select( editSiteStore ).getEditedPostType() | ||
) | ||
); | ||
const { __unstableSetEditorMode: setEditorMode } = | ||
useDispatch( blockEditorStore ); | ||
const { __unstableGetEditorMode: getEditorMode } = | ||
useSelect( blockEditorStore ); | ||
const hasEditorCanvasContainer = useHasEditorCanvasContainer(); | ||
const location = useLocation(); | ||
|
||
const isMobile = useViewportMatch( 'medium', '<' ); | ||
const TagName = ! isMobile ? VisuallyHidden : 'div'; | ||
|
@@ -45,6 +65,32 @@ export default function InserterSidebar() { | |
libraryRef.current.focusSearch(); | ||
}, [] ); | ||
|
||
const handleSelectTab = useCallback( | ||
( tab ) => { | ||
// Only enter the zoom-out mode when it's not in the focus mode. | ||
if ( ! hasEditorCanvasContainer && ! isFocusMode ) { | ||
// Enter the zoom-out mode when selecting the patterns tab and exit otherwise. | ||
if ( tab === 'patterns' ) { | ||
setEditorMode( 'zoom-out' ); | ||
} else if ( getEditorMode() === 'zoom-out' ) { | ||
setEditorMode( 'edit' ); | ||
} | ||
} | ||
}, | ||
[ getEditorMode, setEditorMode, isFocusMode, hasEditorCanvasContainer ] | ||
); | ||
|
||
const previousLocationRef = useRef( location ); | ||
useEffect( | ||
function closeInserterOnNavigate() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, we should find a better way and place to manage this when we have a better routing system. |
||
if ( location !== previousLocationRef.current ) { | ||
previousLocationRef.current = location; | ||
setIsInserterOpened( false ); | ||
} | ||
}, | ||
[ location, setIsInserterOpened ] | ||
); | ||
|
||
return ( | ||
<div | ||
ref={ inserterDialogRef } | ||
|
@@ -72,6 +118,7 @@ export default function InserterSidebar() { | |
} | ||
__experimentalShouldZoomPatterns | ||
ref={ libraryRef } | ||
onSelectTab={ handleSelectTab } | ||
/> | ||
</div> | ||
</div> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to mark this private if we ever want to land this on trunk.