forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Modify content-locked menu item not showing if the block is not s…
…elected (WordPress#61605) Co-authored-by: kevin940726 <kevin940726@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
- Loading branch information
Showing
6 changed files
with
83 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ModifyContentLockMenuItem } from './modify-content-lock-menu-item'; |
58 changes: 58 additions & 0 deletions
58
packages/block-editor/src/components/content-lock/modify-content-lock-menu-item.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,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { MenuItem } from '@wordpress/components'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { _x } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
// The implementation of content locking is mainly in this file, although the mechanism | ||
// to stop temporarily editing as blocks when an outside block is selected is on component StopEditingAsBlocksOnOutsideSelect | ||
// at block-editor/src/components/block-list/index.js. | ||
// Besides the components on this file and the file referenced above the implementation | ||
// also includes artifacts on the store (actions, reducers, and selector). | ||
|
||
export function ModifyContentLockMenuItem( { clientId, onClose } ) { | ||
const { templateLock, isLockedByParent, isEditingAsBlocks } = useSelect( | ||
( select ) => { | ||
const { | ||
getContentLockingParent, | ||
getTemplateLock, | ||
getTemporarilyEditingAsBlocks, | ||
} = unlock( select( blockEditorStore ) ); | ||
return { | ||
templateLock: getTemplateLock( clientId ), | ||
isLockedByParent: !! getContentLockingParent( clientId ), | ||
isEditingAsBlocks: getTemporarilyEditingAsBlocks() === clientId, | ||
}; | ||
}, | ||
[ clientId ] | ||
); | ||
const blockEditorActions = useDispatch( blockEditorStore ); | ||
const isContentLocked = | ||
! isLockedByParent && templateLock === 'contentOnly'; | ||
if ( ! isContentLocked && ! isEditingAsBlocks ) { | ||
return null; | ||
} | ||
|
||
const { modifyContentLockBlock } = unlock( blockEditorActions ); | ||
const showStartEditingAsBlocks = ! isEditingAsBlocks && isContentLocked; | ||
|
||
return ( | ||
showStartEditingAsBlocks && ( | ||
<MenuItem | ||
onClick={ () => { | ||
modifyContentLockBlock( clientId ); | ||
onClose(); | ||
} } | ||
> | ||
{ _x( 'Modify', 'Unlock content locked blocks' ) } | ||
</MenuItem> | ||
) | ||
); | ||
} |
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