From 922a1b3f289ce534b1c1189eb0d4796057c5c27a Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 24 Oct 2018 16:47:15 -0400 Subject: [PATCH 1/2] Editor: Flatten Inserter mapSelectToProps --- .../editor/src/components/inserter/index.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/editor/src/components/inserter/index.js b/packages/editor/src/components/inserter/index.js index 73a971a7de5c73..ad36eb19491e23 100644 --- a/packages/editor/src/components/inserter/index.js +++ b/packages/editor/src/components/inserter/index.js @@ -96,24 +96,24 @@ export default compose( [ getInserterItems, getBlockOrder, } = select( 'core/editor' ); + const insertionPoint = getBlockInsertionPoint(); - const parentId = rootClientId || insertionPoint.rootClientId; + if ( rootClientId === undefined ) { + rootClientId = insertionPoint.rootClientId; + } + return { title: getEditedPostAttribute( 'title' ), - insertionPoint: { - rootClientId: parentId, - layout: rootClientId ? layout : insertionPoint.layout, - index: rootClientId ? getBlockOrder( rootClientId ).length : insertionPoint.index, - }, + layout: rootClientId ? layout : insertionPoint.layout, + index: rootClientId ? getBlockOrder( rootClientId ).length : insertionPoint.index, selectedBlock: getSelectedBlock(), - items: getInserterItems( parentId ), - rootClientId: parentId, + items: getInserterItems( rootClientId ), + rootClientId, }; } ), withDispatch( ( dispatch, ownProps ) => ( { onInsertBlock: ( item ) => { - const { selectedBlock, insertionPoint } = ownProps; - const { index, rootClientId, layout } = insertionPoint; + const { selectedBlock, index, rootClientId, layout } = ownProps; const { name, initialAttributes } = item; const insertedBlock = createBlock( name, { ...initialAttributes, layout } ); if ( selectedBlock && isUnmodifiedDefaultBlock( selectedBlock ) ) { From 6c91fbeef098d4196763ec5bebf10d98cc3d44d2 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 26 Oct 2018 10:58:51 -0400 Subject: [PATCH 2/2] Inserter: Assign layout, index as undefined rootClientId fallback --- packages/editor/src/components/inserter/index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/components/inserter/index.js b/packages/editor/src/components/inserter/index.js index ad36eb19491e23..8a38b152dd0ace 100644 --- a/packages/editor/src/components/inserter/index.js +++ b/packages/editor/src/components/inserter/index.js @@ -94,20 +94,24 @@ export default compose( [ getBlockInsertionPoint, getSelectedBlock, getInserterItems, - getBlockOrder, } = select( 'core/editor' ); - const insertionPoint = getBlockInsertionPoint(); + let index; if ( rootClientId === undefined ) { - rootClientId = insertionPoint.rootClientId; + // Unless explicitly provided, the default insertion point provided + // by the store occurs immediately following the selected block. + // Otherwise, the default behavior for an undefined index is to + // append block to the end of the rootClientId context. + const insertionPoint = getBlockInsertionPoint(); + ( { rootClientId, layout, index } = insertionPoint ); } return { title: getEditedPostAttribute( 'title' ), - layout: rootClientId ? layout : insertionPoint.layout, - index: rootClientId ? getBlockOrder( rootClientId ).length : insertionPoint.index, selectedBlock: getSelectedBlock(), items: getInserterItems( rootClientId ), + layout, + index, rootClientId, }; } ),