-
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.
Merge branch 'trunk' into add/link-color-theme-support
- Loading branch information
Showing
87 changed files
with
2,041 additions
and
419 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
packages/block-editor/src/components/block-removal-warning-modal/index.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,94 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect } from '@wordpress/element'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { | ||
Modal, | ||
Button, | ||
__experimentalHStack as HStack, | ||
} from '@wordpress/components'; | ||
import { __, _n } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
// In certain editing contexts, we'd like to prevent accidental removal of | ||
// important blocks. For example, in the site editor, the Query Loop block is | ||
// deemed important. In such cases, we'll ask the user for confirmation that | ||
// they intended to remove such block(s). | ||
// | ||
// @see https://github.com/WordPress/gutenberg/pull/51145 | ||
export const blockTypePromptMessages = { | ||
'core/query': __( 'Query Loop displays a list of posts or pages.' ), | ||
'core/post-content': __( | ||
'Post Content displays the content of a post or page.' | ||
), | ||
}; | ||
|
||
export function BlockRemovalWarningModal() { | ||
const { clientIds, selectPrevious, blockNamesForPrompt } = useSelect( | ||
( select ) => | ||
unlock( select( blockEditorStore ) ).getRemovalPromptData() | ||
); | ||
|
||
const { | ||
clearRemovalPrompt, | ||
toggleRemovalPromptSupport, | ||
privateRemoveBlocks, | ||
} = unlock( useDispatch( blockEditorStore ) ); | ||
|
||
// Signalling the removal prompt is in place. | ||
useEffect( () => { | ||
toggleRemovalPromptSupport( true ); | ||
return () => { | ||
toggleRemovalPromptSupport( false ); | ||
}; | ||
}, [ toggleRemovalPromptSupport ] ); | ||
|
||
if ( ! blockNamesForPrompt ) { | ||
return; | ||
} | ||
|
||
const onConfirmRemoval = () => { | ||
privateRemoveBlocks( clientIds, selectPrevious, /* force */ true ); | ||
clearRemovalPrompt(); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
title={ __( 'Are you sure?' ) } | ||
onRequestClose={ clearRemovalPrompt } | ||
> | ||
{ blockNamesForPrompt.length === 1 ? ( | ||
<p>{ blockTypePromptMessages[ blockNamesForPrompt[ 0 ] ] }</p> | ||
) : ( | ||
<ul style={ { listStyleType: 'disc', paddingLeft: '1rem' } }> | ||
{ blockNamesForPrompt.map( ( name ) => ( | ||
<li key={ name }> | ||
{ blockTypePromptMessages[ name ] } | ||
</li> | ||
) ) } | ||
</ul> | ||
) } | ||
<p> | ||
{ _n( | ||
'Removing this block is not advised.', | ||
'Removing these blocks is not advised.', | ||
blockNamesForPrompt.length | ||
) } | ||
</p> | ||
<HStack justify="right"> | ||
<Button variant="tertiary" onClick={ clearRemovalPrompt }> | ||
{ __( 'Cancel' ) } | ||
</Button> | ||
<Button variant="primary" onClick={ onConfirmRemoval }> | ||
{ __( 'Delete' ) } | ||
</Button> | ||
</HStack> | ||
</Modal> | ||
); | ||
} |
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
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.