From 3ce2a7c81014ba8286ea417c80209253de4d922d Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Wed, 12 May 2021 17:49:20 -0700 Subject: [PATCH 1/5] [RNMobile] Added layoutGridBlock enabling capabilities flag to mobile gutenberg bridge --- .../java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt | 3 +++ packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift | 1 + 2 files changed, 4 insertions(+) diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt index 129a0fd0437ffb..86473af44afb77 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt @@ -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, @@ -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) @@ -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" diff --git a/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift b/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift index f89563063e63a5..03227395048328 100644 --- a/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift +++ b/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift @@ -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 From 0426002b0f0aa189081060bc56a925f70f714b89 Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Wed, 2 Jun 2021 13:52:27 -0700 Subject: [PATCH 2/5] Mobile: Disable the block inserter if the there are no blocks to insert This fixes a but in the block inserter button and make the feature match the web functionality. --- .../header/header-toolbar/index.native.js | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/edit-post/src/components/header/header-toolbar/index.native.js b/packages/edit-post/src/components/header/header-toolbar/index.native.js index 903f8c0a8fee66..1f81ca59404202 100644 --- a/packages/edit-post/src/components/header/header-toolbar/index.native.js +++ b/packages/edit-post/src/components/header/header-toolbar/index.native.js @@ -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 ); From 8d4acbae740593de9037bfea8d0b8254cdccb949 Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Wed, 2 Jun 2021 15:32:26 -0700 Subject: [PATCH 3/5] Mobile: Disable actions that involve duplicating if the template is locked. --- .../block-actions-menu.native.js | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js b/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js index acfd59b8db8c5c..6deb525f73c6a3 100644 --- a/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js +++ b/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js @@ -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 */ @@ -15,6 +15,7 @@ import { import { getBlockType, getDefaultBlockName, + hasBlockSupport, serialize, rawHandler, createBlock, @@ -43,6 +44,8 @@ const BlockActionsMenu = ( { canInsertBlockType, getBlocksByClientId, isEmptyDefaultBlock, + isLocked, + canDuplicate, isFirst, isLast, isReusableBlockType, @@ -203,16 +206,22 @@ 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 null; + } + function onPasteBlock() { if ( ! clipboard ) { return; @@ -290,6 +299,7 @@ export default compose( getBlocksByClientId, getSelectedBlockClientIds, canInsertBlockType, + getTemplateLock, } = select( blockEditorStore ); const normalizedClientIds = castArray( clientIds ); const block = getBlock( normalizedClientIds ); @@ -306,11 +316,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 @@ -335,6 +356,8 @@ export default compose( currentIndex: firstIndex, getBlocksByClientId, isEmptyDefaultBlock, + isLocked, + canDuplicate, isFirst: firstIndex === 0, isLast: lastIndex === blockOrder.length - 1, isReusableBlockType, From 32dd651e5625bcf8809499318714d126673e3a6e Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Thu, 3 Jun 2021 15:14:26 -0700 Subject: [PATCH 4/5] Disable the Block Actions when there are non instead of not showing them --- .../block-mobile-toolbar/block-actions-menu.native.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js b/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js index 6deb525f73c6a3..152051eabc94a4 100644 --- a/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js +++ b/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js @@ -219,7 +219,11 @@ const BlockActionsMenu = ( { // End early if there are no options to show. if ( ! options.length ) { - return null; + return } function onPasteBlock() { From 2cf971beddd80386f8e9f9811a4fafdc79930961 Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Thu, 3 Jun 2021 15:58:46 -0700 Subject: [PATCH 5/5] Minor code style fixes --- .../block-actions-menu.native.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js b/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js index 152051eabc94a4..d67b4beba66290 100644 --- a/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js +++ b/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js @@ -219,11 +219,13 @@ const BlockActionsMenu = ( { // End early if there are no options to show. if ( ! options.length ) { - return + return ( + + ); } function onPasteBlock() {