-
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.
[RNMobile] Add Group and Ungroup block actions (#50693)
* Add `useConvertToGroupButtons` hook Most of the logic of this hook has been extracted from `ConvertToGroupButton` component. The main difference is that we return the configuration for the block actions instead of a component. * Add Group and Ungroup options to block actions menu * Remove `canUnwrap` option from `getBlockTransformOptions` test helper * Update tests for Group, Quote and Columns blocks
- Loading branch information
Showing
9 changed files
with
120 additions
and
43 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
80 changes: 79 additions & 1 deletion
80
packages/block-editor/src/components/convert-to-group-buttons/index.native.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 |
---|---|---|
@@ -1 +1,79 @@ | ||
export default () => null; | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { switchToBlockType } from '@wordpress/blocks'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { store as noticesStore } from '@wordpress/notices'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import useConvertToGroupButtonProps from './use-convert-to-group-button-props'; | ||
|
||
function useConvertToGroupButtons( { | ||
clientIds, | ||
onUngroup, | ||
blocksSelection, | ||
groupingBlockName, | ||
} ) { | ||
const { replaceBlocks } = useDispatch( blockEditorStore ); | ||
const { createSuccessNotice } = useDispatch( noticesStore ); | ||
const onConvertToGroup = () => { | ||
// Activate the `transform` on the Grouping Block which does the conversion. | ||
const newBlocks = switchToBlockType( | ||
blocksSelection, | ||
groupingBlockName | ||
); | ||
if ( newBlocks ) { | ||
replaceBlocks( clientIds, newBlocks ); | ||
} | ||
}; | ||
|
||
const onConvertFromGroup = () => { | ||
let innerBlocks = blocksSelection[ 0 ].innerBlocks; | ||
if ( ! innerBlocks.length ) { | ||
return; | ||
} | ||
if ( onUngroup ) { | ||
innerBlocks = onUngroup( | ||
blocksSelection[ 0 ].attributes, | ||
blocksSelection[ 0 ].innerBlocks | ||
); | ||
} | ||
replaceBlocks( clientIds, innerBlocks ); | ||
}; | ||
|
||
return { | ||
group: { | ||
id: 'groupButtonOption', | ||
label: _x( 'Group', 'verb' ), | ||
value: 'groupButtonOption', | ||
onSelect: () => { | ||
onConvertToGroup(); | ||
createSuccessNotice( | ||
// translators: displayed right after the block is grouped | ||
__( 'Block grouped' ) | ||
); | ||
}, | ||
}, | ||
ungroup: { | ||
id: 'ungroupButtonOption', | ||
label: _x( | ||
'Ungroup', | ||
'Ungrouping blocks from within a grouping block back into individual blocks within the Editor' | ||
), | ||
value: 'ungroupButtonOption', | ||
onSelect: () => { | ||
onConvertFromGroup(); | ||
createSuccessNotice( | ||
// translators: displayed right after the block is ungrouped. | ||
__( 'Block ungrouped' ) | ||
); | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
export { useConvertToGroupButtons, useConvertToGroupButtonProps }; |
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
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