Skip to content

Commit

Permalink
Switch attributesToCopy to be an array of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Jan 20, 2022
1 parent 8f7dc06 commit 401358f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
9 changes: 3 additions & 6 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} attributesToCopy Attributes to be copied from adjecent blocks when inserted.
*/
export const __experimentalGetDirectInsertBlock = createSelector(
( state, rootClientId = null ) => {
Expand Down
22 changes: 11 additions & 11 deletions packages/block-library/src/buttons/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {} } } ) {
Expand Down

0 comments on commit 401358f

Please sign in to comment.