Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { Platform, findNodeHandle } from 'react-native';
import { partial, first, castArray, last, compact } from 'lodash';
import { partial, first, castArray, last, compact, every } from 'lodash';
/**
* WordPress dependencies
*/
Expand All @@ -15,6 +15,7 @@ import {
import {
getBlockType,
getDefaultBlockName,
hasBlockSupport,
serialize,
rawHandler,
createBlock,
Expand Down Expand Up @@ -43,6 +44,8 @@ const BlockActionsMenu = ( {
canInsertBlockType,
getBlocksByClientId,
isEmptyDefaultBlock,
isLocked,
canDuplicate,
isFirst,
isLast,
isReusableBlockType,
Expand Down Expand Up @@ -203,16 +206,28 @@ const BlockActionsMenu = ( {
wrapBlockMover && allOptions.backwardButton,
wrapBlockMover && allOptions.forwardButton,
wrapBlockSettings && allOptions.settings,
selectedBlockPossibleTransformations.length &&
! isLocked &&
selectedBlockPossibleTransformations.length &&
allOptions.transformButton,
allOptions.copyButton,
allOptions.cutButton,
isPasteEnabled && allOptions.pasteButton,
allOptions.duplicateButton,
canDuplicate && allOptions.copyButton,
canDuplicate && allOptions.cutButton,
canDuplicate && isPasteEnabled && allOptions.pasteButton,
canDuplicate && allOptions.duplicateButton,
isReusableBlockType && allOptions.convertToRegularBlocks,
allOptions.delete,
! isLocked && allOptions.delete,
] );

// End early if there are no options to show.
if ( ! options.length ) {
return (
<ToolbarButton
title={ __( 'Open Block Actions Menu' ) }
icon={ moreHorizontalMobile }
disabled={ true }
/>
);
}

function onPasteBlock() {
if ( ! clipboard ) {
return;
Expand Down Expand Up @@ -290,6 +305,7 @@ export default compose(
getBlocksByClientId,
getSelectedBlockClientIds,
canInsertBlockType,
getTemplateLock,
} = select( blockEditorStore );
const normalizedClientIds = castArray( clientIds );
const block = getBlock( normalizedClientIds );
Expand All @@ -306,11 +322,22 @@ export default compose(
rootClientId
);

const innerBlocks = getBlocksByClientId( clientIds );

const canDuplicate = every( innerBlocks, ( innerBlock ) => {
return (
!! innerBlock &&
hasBlockSupport( innerBlock.name, 'multiple', true ) &&
canInsertBlockType( innerBlock.name, rootClientId )
);
} );

const isDefaultBlock = blockName === getDefaultBlockName();
const isEmptyContent = block?.attributes.content === '';
const isExactlyOneBlock = blockOrder.length === 1;
const isEmptyDefaultBlock =
isExactlyOneBlock && isDefaultBlock && isEmptyContent;
const isLocked = !! getTemplateLock( rootClientId );

const selectedBlockClientId = first( getSelectedBlockClientIds() );
const selectedBlock = selectedBlockClientId
Expand All @@ -335,6 +362,8 @@ export default compose(
currentIndex: firstIndex,
getBlocksByClientId,
isEmptyDefaultBlock,
isLocked,
canDuplicate,
isFirst: firstIndex === 0,
isLast: lastIndex === blockOrder.length - 1,
isReusableBlockType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,28 @@ function HeaderToolbar( {
}

export default compose( [
withSelect( ( select ) => ( {
hasRedo: select( editorStore ).hasEditorRedo(),
hasUndo: select( editorStore ).hasEditorUndo(),
// This setting (richEditingEnabled) should not live in the block editor's setting.
showInserter:
select( editPostStore ).getEditorMode() === 'visual' &&
select( editorStore ).getEditorSettings().richEditingEnabled,
isTextModeEnabled: select( editPostStore ).getEditorMode() === 'text',
isRTL: select( blockEditorStore ).getSettings().isRTL,
} ) ),
withSelect( ( select ) => {
const {
getBlockRootClientId,
getBlockSelectionEnd,
hasInserterItems,
getEditorSettings,
} = select( editorStore );
return {
hasRedo: select( editorStore ).hasEditorRedo(),
hasUndo: select( editorStore ).hasEditorUndo(),
// This setting (richEditingEnabled) should not live in the block editor's setting.
showInserter:
select( editPostStore ).getEditorMode() === 'visual' &&
getEditorSettings().richEditingEnabled &&
hasInserterItems(
getBlockRootClientId( getBlockSelectionEnd() )
),
isTextModeEnabled:
select( editPostStore ).getEditorMode() === 'text',
isRTL: select( blockEditorStore ).getSettings().isRTL,
};
} ),
withDispatch( ( dispatch ) => {
const { clearSelectedBlock } = dispatch( blockEditorStore );
const { togglePostTitleSelection } = dispatch( editorStore );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle

data class GutenbergProps @JvmOverloads constructor(
val enableContactInfoBlock: Boolean,
val enableLayoutGridBlock: Boolean,
val enableMediaFilesCollectionBlocks: Boolean,
val enableMentions: Boolean,
val enableXPosts: Boolean,
Expand Down Expand Up @@ -42,6 +43,7 @@ data class GutenbergProps @JvmOverloads constructor(
putBoolean(PROP_CAPABILITIES_MENTIONS, enableMentions)
putBoolean(PROP_CAPABILITIES_XPOSTS, enableXPosts)
putBoolean(PROP_CAPABILITIES_CONTACT_INFO_BLOCK, enableContactInfoBlock)
putBoolean(PROP_CAPABILITIES_LAYOUT_GRID_BLOCK, enableLayoutGridBlock)
putBoolean(PROP_CAPABILITIES_MEDIAFILES_COLLECTION_BLOCK, enableMediaFilesCollectionBlocks)
putBoolean(PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR, enableUnsupportedBlockEditor)
putBoolean(PROP_CAPABILITIES_CAN_ENABLE_UNSUPPORTED_BLOCK_EDITOR, canEnableUnsupportedBlockEditor)
Expand Down Expand Up @@ -70,6 +72,7 @@ data class GutenbergProps @JvmOverloads constructor(

const val PROP_CAPABILITIES = "capabilities"
const val PROP_CAPABILITIES_CONTACT_INFO_BLOCK = "contactInfoBlock"
const val PROP_CAPABILITIES_LAYOUT_GRID_BLOCK = "layoutGridBlock"
const val PROP_CAPABILITIES_MEDIAFILES_COLLECTION_BLOCK = "mediaFilesCollectionBlock"
const val PROP_CAPABILITIES_MENTIONS = "mentions"
const val PROP_CAPABILITIES_XPOSTS = "xposts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public struct MediaInfo: Encodable {
/// Definition of capabilities to enable in the Block Editor
public enum Capabilities: String {
case contactInfoBlock
case layoutGridBlock
case mediaFilesCollectionBlock
case mentions
case xposts
Expand Down