-
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.
- Loading branch information
Showing
3 changed files
with
71 additions
and
68 deletions.
There are no files selected for viewing
66 changes: 0 additions & 66 deletions
66
packages/block-editor/src/components/block-list/disable-non-main-blocks.js
This file was deleted.
Oops, something went wrong.
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
68 changes: 68 additions & 0 deletions
68
packages/block-editor/src/components/block-list/use-zoom-out-block-editing-mode.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,68 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import { useBlockEditContext } from '../block-edit/context'; | ||
|
||
export default function useZoomOutBlockEditingMode() { | ||
const { clientId: rootClientId = '' } = useBlockEditContext(); | ||
|
||
const { unsetBlockEditingMode, setBlockEditingMode } = | ||
useDispatch( blockEditorStore ); | ||
|
||
const { isZoomOutMode, sectionsContainerClientId, sectionsClientIds } = | ||
useSelect( ( select ) => { | ||
const { | ||
__unstableGetEditorMode, | ||
getSectionsContainerClientId, | ||
getClientIdsOfDescendants, | ||
} = select( blockEditorStore ); | ||
|
||
// TODO: We need a better API as using the post type | ||
// in block editor package is not allowed. | ||
const postType = select( 'core/editor' ).getCurrentPostType(); | ||
|
||
const _sectionsContainerClientId = | ||
getSectionsContainerClientId( postType ); | ||
|
||
return { | ||
isZoomOutMode: __unstableGetEditorMode() === 'zoom-out', | ||
sectionsContainerClientId: _sectionsContainerClientId, | ||
sectionsClientIds: getClientIdsOfDescendants( | ||
_sectionsContainerClientId | ||
), | ||
}; | ||
}, [] ); | ||
|
||
useEffect( () => { | ||
if ( isZoomOutMode ) { | ||
setBlockEditingMode( rootClientId, 'disabled' ); | ||
setBlockEditingMode( sectionsContainerClientId, 'contentOnly' ); | ||
sectionsClientIds.forEach( ( clientId ) => { | ||
setBlockEditingMode( clientId, 'default' ); | ||
} ); | ||
|
||
return () => { | ||
sectionsClientIds.forEach( ( clientId ) => { | ||
unsetBlockEditingMode( clientId ); | ||
} ); | ||
unsetBlockEditingMode( sectionsContainerClientId ); | ||
unsetBlockEditingMode( rootClientId ); | ||
}; | ||
} | ||
}, [ | ||
isZoomOutMode, | ||
rootClientId, | ||
sectionsContainerClientId, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
...sectionsClientIds, | ||
setBlockEditingMode, | ||
unsetBlockEditingMode, | ||
] ); | ||
} |