diff --git a/packages/blocks/src/api/parser/apply-block-deprecated-versions.js b/packages/blocks/src/api/parser/apply-block-deprecated-versions.js index 3b0b34090ce9ab..4c6e45bdfa035e 100644 --- a/packages/blocks/src/api/parser/apply-block-deprecated-versions.js +++ b/packages/blocks/src/api/parser/apply-block-deprecated-versions.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { omit, castArray } from 'lodash'; +import { castArray } from 'lodash'; /** * Internal dependencies @@ -10,6 +10,7 @@ import { DEPRECATED_ENTRY_KEYS } from '../constants'; import { validateBlock } from '../validation'; import { getBlockAttributes } from './get-block-attributes'; import { applyBuiltInValidationFixes } from './apply-built-in-validation-fixes'; +import { omit } from '../utils'; /** * Function that takes no arguments and always returns false. diff --git a/packages/blocks/src/api/parser/fix-custom-classname.js b/packages/blocks/src/api/parser/fix-custom-classname.js index 2628f0e967e7ff..d72065cd59222b 100644 --- a/packages/blocks/src/api/parser/fix-custom-classname.js +++ b/packages/blocks/src/api/parser/fix-custom-classname.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { omit } from 'lodash'; - /** * Internal dependencies */ @@ -52,9 +47,8 @@ export function fixCustomClassname( blockAttributes, blockType, innerHTML ) { // attributes, with the exception of `className`. This will determine // the default set of classes. From there, any difference in innerHTML // can be considered as custom classes. - const attributesSansClassName = omit( blockAttributes, [ - 'className', - ] ); + const { className: omittedClassName, ...attributesSansClassName } = + blockAttributes; const serialized = getSaveContent( blockType, attributesSansClassName ); const defaultClasses = getHTMLRootElementClasses( serialized ); const actualClasses = getHTMLRootElementClasses( innerHTML ); diff --git a/packages/blocks/src/api/test/registration.js b/packages/blocks/src/api/test/registration.js index 5abd16d877ea58..490b547e7ef593 100644 --- a/packages/blocks/src/api/test/registration.js +++ b/packages/blocks/src/api/test/registration.js @@ -31,13 +31,11 @@ import { unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase } from '../registration'; import { BLOCK_ICON_DEFAULT, DEPRECATED_ENTRY_KEYS } from '../constants'; +import { omit } from '../utils'; import { store as blocksStore } from '../../store'; const noop = () => {}; -const omit = ( obj, keys ) => - Object.fromEntries( - Object.entries( obj ).filter( ( [ key ] ) => ! keys.includes( key ) ) - ); + const pick = ( obj, keys ) => Object.fromEntries( Object.entries( obj ).filter( ( [ key ] ) => keys.includes( key ) ) diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index 391bac42245dcd..ba094e073fe2b1 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -304,3 +304,17 @@ export function __experimentalGetBlockAttributesNamesByRole( name, role ) { attributes[ attributeName ]?.__experimentalRole === role ); } + +/** + * Return a new object with the specified keys omitted. + * + * @param {Object} object Original object. + * @param {Array} keys Keys to be omitted. + * + * @return {Object} Object with omitted keys. + */ +export function omit( object, keys ) { + return Object.fromEntries( + Object.entries( object ).filter( ( [ key ] ) => ! keys.includes( key ) ) + ); +} diff --git a/packages/blocks/src/store/actions.js b/packages/blocks/src/store/actions.js index f7d5f9b2bc3304..7d178969615cfd 100644 --- a/packages/blocks/src/store/actions.js +++ b/packages/blocks/src/store/actions.js @@ -2,7 +2,7 @@ * External dependencies */ import { isPlainObject } from 'is-plain-object'; -import { castArray, omit, pick, some } from 'lodash'; +import { castArray, pick, some } from 'lodash'; /** * WordPress dependencies @@ -12,7 +12,7 @@ import { applyFilters } from '@wordpress/hooks'; /** * Internal dependencies */ -import { isValidIcon, normalizeIconObject } from '../api/utils'; +import { isValidIcon, normalizeIconObject, omit } from '../api/utils'; import { DEPRECATED_ENTRY_KEYS } from '../api/constants'; /** @typedef {import('../api/registration').WPBlockVariation} WPBlockVariation */ diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index b0f5167c12fdb0..242876476f14ff 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { filter, find, get, isEmpty, map, mapValues, omit } from 'lodash'; +import { filter, find, get, isEmpty, map, mapValues } from 'lodash'; /** * WordPress dependencies @@ -9,6 +9,11 @@ import { filter, find, get, isEmpty, map, mapValues, omit } from 'lodash'; import { combineReducers } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; +/** + * Internal dependencies + */ +import { omit } from '../api/utils'; + /** * @typedef {Object} WPBlockCategory *