-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Modify button not showing if it's not selected
- Loading branch information
1 parent
c90eb55
commit 77ff827
Showing
6 changed files
with
81 additions
and
44 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 { __ } 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(); | ||
} } | ||
> | ||
{ __( 'Modify' ) } | ||
</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