From 401358fc268b6cc74033650a3b203adb032b52b8 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Thu, 20 Jan 2022 14:10:55 +1100 Subject: [PATCH] Switch attributesToCopy to be an array of strings --- .../src/components/inserter/index.js | 9 +++----- packages/block-editor/src/store/selectors.js | 12 +++++----- packages/block-library/src/buttons/edit.js | 22 +++++++++---------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/block-editor/src/components/inserter/index.js b/packages/block-editor/src/components/inserter/index.js index e20ea901c070a..c2fa59c92c2d8 100644 --- a/packages/block-editor/src/components/inserter/index.js +++ b/packages/block-editor/src/components/inserter/index.js @@ -303,15 +303,12 @@ export default compose( [ } // Copy over only those attributes flagged to be copied. - for ( const attribute in attributesToCopy ) { - if ( - attributesToCopy[ attribute ] && - adjacentAttributes.hasOwnProperty( attribute ) - ) { + attributesToCopy.forEach( ( attribute ) => { + if ( adjacentAttributes.hasOwnProperty( attribute ) ) { result[ attribute ] = adjacentAttributes[ attribute ]; } - } + } ); return result; } diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 6e36001935178..3ad6ce359ad55 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1844,15 +1844,15 @@ export const __experimentalGetAllowedBlocks = createSelector( /** * Returns the block to be directly inserted by the block appender. * - * @param {Object} state Editor state. - * @param {?string} rootClientId Optional root client ID of block list. + * @param {Object} state Editor state. + * @param {?string} rootClientId Optional root client ID of block list. * - * @return {?WPDirectInsertBlock} The block type to be directly inserted. + * @return {?WPDirectInsertBlock} The block type to be directly inserted. * * @typedef {Object} WPDirectInsertBlock - * @property {string} name The type of block. - * @property {?Object} attributes Attributes to pass to the newly created block. - * @property {?Object} attributesToCopy Attributes to be copied from adjecent blocks when inserted. + * @property {string} name The type of block. + * @property {?Object} attributes Attributes to pass to the newly created block. + * @property {?Array} attributesToCopy Attributes to be copied from adjecent blocks when inserted. */ export const __experimentalGetDirectInsertBlock = createSelector( ( state, rootClientId = null ) => { diff --git a/packages/block-library/src/buttons/edit.js b/packages/block-library/src/buttons/edit.js index e7cddeedb3330..05c95609c7482 100644 --- a/packages/block-library/src/buttons/edit.js +++ b/packages/block-library/src/buttons/edit.js @@ -17,17 +17,17 @@ const ALLOWED_BLOCKS = [ buttonBlockName ]; const DEFAULT_BLOCK = { name: buttonBlockName, - attributesToCopy: { - backgroundColor: true, - border: true, - className: true, - fontSize: true, - fontFamily: true, - gradient: true, - style: true, - textColor: true, - width: true, - }, + attributesToCopy: [ + 'backgroundColor', + 'border', + 'className', + 'fontFamily', + 'fontSize', + 'gradient', + 'style', + 'textColor', + 'width', + ], }; function ButtonsEdit( { attributes: { layout = {} } } ) {