-
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
- Loading branch information
1 parent
f83c592
commit 9ac649f
Showing
18 changed files
with
377 additions
and
409 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( canvasMode ) { | ||
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 && | ||
canvasMode === 'edit' && | ||
getPreference( 'core', 'showListViewByDefault' ) && | ||
! getPreference( 'core', 'distractionFree' ) | ||
) { | ||
setIsListViewOpened( true ); | ||
} else { | ||
setIsListViewOpened( false ); | ||
} | ||
} ); | ||
}, [ | ||
canvasMode, | ||
registry, | ||
clearSelectedBlock, | ||
setDeviceType, | ||
closePublishSidebar, | ||
setIsInserterOpened, | ||
setIsListViewOpened, | ||
getPreference, | ||
] ); | ||
} |
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
Oops, something went wrong.