From d9e3c24218908f4408da13cdfb4a33d0e0fab251 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 26 May 2020 10:25:40 +1000 Subject: [PATCH] Prototype move blocks between levels with keyboard --- .../developers/data/data-core-block-editor.md | 20 ++++++ .../src/components/block-actions/index.js | 9 ++- .../src/components/block-list/breadcrumb.js | 16 ++++- .../src/components/block-list/style.scss | 26 +++++++ .../src/components/writing-flow/index.js | 72 +++++++++++++++++-- packages/block-editor/src/store/actions.js | 12 ++++ packages/block-editor/src/store/reducer.js | 19 +++++ packages/block-editor/src/store/selectors.js | 11 +++ 8 files changed, 176 insertions(+), 9 deletions(-) diff --git a/docs/designers-developers/developers/data/data-core-block-editor.md b/docs/designers-developers/developers/data/data-core-block-editor.md index 23e48402fb1cb..6ff6c95e15453 100644 --- a/docs/designers-developers/developers/data/data-core-block-editor.md +++ b/docs/designers-developers/developers/data/data-core-block-editor.md @@ -758,6 +758,18 @@ _Returns_ - `?boolean`: Whether the insertion point is visible or not. +# **isBlockMovingMode** + +Returns whether block moving mode is enabled. + +_Parameters_ + +- _state_ `Object`: Editor state. + +_Returns_ + +- `string`: Client Id of moving block. + # **isBlockMultiSelected** Returns true if the client ID occurs within the block multi-selection, or @@ -1255,6 +1267,14 @@ _Parameters_ - _clientId_ `string`: Block client ID. +# **setBlockMovingMode** + +Generators that triggers an action used to enable or disable the block moving mode. + +_Parameters_ + +- _isBlockMovingMode_ `string`: Enable/Disable block moving mode. + # **setHasControlledInnerBlocks** Returns an action object that sets whether the block has controlled innerblocks. diff --git a/packages/block-editor/src/components/block-actions/index.js b/packages/block-editor/src/components/block-actions/index.js index 9b890ee5c4ed7..e71e86e5d3069 100644 --- a/packages/block-editor/src/components/block-actions/index.js +++ b/packages/block-editor/src/components/block-actions/index.js @@ -19,6 +19,7 @@ function BlockActions( { onGroup, onInsertAfter, onInsertBefore, + onMoveTo, onRemove, onUngroup, blocks, @@ -31,6 +32,7 @@ function BlockActions( { onGroup, onInsertAfter, onInsertBefore, + onMoveTo, onRemove, onUngroup, blocks, @@ -73,13 +75,14 @@ export default compose( [ } ), withDispatch( ( dispatch, props, { select } ) => { const { clientIds, blocks } = props; - const { removeBlocks, replaceBlocks, duplicateBlocks, insertAfterBlock, insertBeforeBlock, + setBlockMovingMode, + setNavigationMode, } = dispatch( 'core/block-editor' ); return { @@ -95,6 +98,10 @@ export default compose( [ onInsertAfter() { insertAfterBlock( last( castArray( clientIds ) ) ); }, + onMoveTo() { + setNavigationMode( true ); + setBlockMovingMode( clientIds[ 0 ] ); + }, onGroup() { if ( ! blocks.length ) { return; diff --git a/packages/block-editor/src/components/block-list/breadcrumb.js b/packages/block-editor/src/components/block-list/breadcrumb.js index 2151725040c46..a837d43a8e769 100644 --- a/packages/block-editor/src/components/block-list/breadcrumb.js +++ b/packages/block-editor/src/components/block-list/breadcrumb.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ @@ -36,16 +41,17 @@ function BlockBreadcrumb( { const { __unstableGetBlockWithoutInnerBlocks, getBlockIndex, + isBlockMovingMode, } = select( 'core/block-editor' ); const index = getBlockIndex( clientId, rootClientId ); const { name, attributes } = __unstableGetBlockWithoutInnerBlocks( clientId ); - return { index, name, attributes }; + return { index, name, attributes, isBlockMovingMode }; }, [ clientId, rootClientId ] ); - const { index, name, attributes } = selected; + const { index, name, attributes, isBlockMovingMode } = selected; const { setNavigationMode, removeBlock } = useDispatch( 'core/block-editor' ); @@ -73,8 +79,12 @@ function BlockBreadcrumb( { moverDirection ); + const classNames = classnames( 'block-editor-block-list__breadcrumb', { + 'is-navigate-mode': !! isBlockMovingMode(), + } ); + return ( -
+