-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor: Remove synchronization of canvas mode into store (#66213)
Co-authored-by: youknowriad <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: ntsekouras <[email protected]>
- Loading branch information
1 parent
0b76a25
commit 58362df
Showing
18 changed files
with
387 additions
and
424 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
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
53 changes: 53 additions & 0 deletions
53
packages/edit-site/src/components/editor/use-adapt-editor-to-canvas.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,53 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useDispatch, useSelect, useRegistry } from '@wordpress/data'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { useLayoutEffect } from '@wordpress/element'; | ||
import { store as preferencesStore } from '@wordpress/preferences'; | ||
|
||
export function useAdaptEditorToCanvas( canvas ) { | ||
const { clearSelectedBlock } = useDispatch( blockEditorStore ); | ||
const { | ||
setDeviceType, | ||
closePublishSidebar, | ||
setIsListViewOpened, | ||
setIsInserterOpened, | ||
} = useDispatch( editorStore ); | ||
const { get: getPreference } = useSelect( preferencesStore ); | ||
const registry = useRegistry(); | ||
useLayoutEffect( () => { | ||
const isMediumOrBigger = | ||
window.matchMedia( '(min-width: 782px)' ).matches; | ||
registry.batch( () => { | ||
clearSelectedBlock(); | ||
setDeviceType( 'Desktop' ); | ||
closePublishSidebar(); | ||
setIsInserterOpened( false ); | ||
|
||
// Check if the block list view should be open by default. | ||
// If `distractionFree` mode is enabled, the block list view should not be open. | ||
// This behavior is disabled for small viewports. | ||
if ( | ||
isMediumOrBigger && | ||
canvas === 'edit' && | ||
getPreference( 'core', 'showListViewByDefault' ) && | ||
! getPreference( 'core', 'distractionFree' ) | ||
) { | ||
setIsListViewOpened( true ); | ||
} else { | ||
setIsListViewOpened( false ); | ||
} | ||
} ); | ||
}, [ | ||
canvas, | ||
registry, | ||
clearSelectedBlock, | ||
setDeviceType, | ||
closePublishSidebar, | ||
setIsInserterOpened, | ||
setIsListViewOpened, | ||
getPreference, | ||
] ); | ||
} |
Oops, something went wrong.