Skip to content

Commit

Permalink
Lodash: Remove from Image block (#50592)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored May 12, 2023
1 parent 7250336 commit 99c3dda
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 32 deletions.
5 changes: 2 additions & 3 deletions packages/block-library/src/image/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -122,7 +121,7 @@ const deprecated = [
title,
} = attributes;

const newRel = isEmpty( rel ) ? undefined : rel;
const newRel = ! rel ? undefined : rel;

const classes = classnames( {
[ `align${ align }` ]: align,
Expand Down Expand Up @@ -202,7 +201,7 @@ const deprecated = [
title,
} = attributes;

const newRel = isEmpty( rel ) ? undefined : rel;
const newRel = ! rel ? undefined : rel;

const classes = classnames( {
[ `align${ align }` ]: align,
Expand Down
5 changes: 3 additions & 2 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -320,7 +319,9 @@ export function ImageEdit( {
'is-resized': !! width || !! height,
[ `size-${ sizeSlug }` ]: sizeSlug,
'has-custom-border':
!! borderProps.className || ! isEmpty( borderProps.style ),
!! borderProps.className ||
( borderProps.style &&
Object.keys( borderProps.style ).length > 0 ),
} );

const blockProps = useBlockProps( {
Expand Down
8 changes: 2 additions & 6 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -480,7 +475,8 @@ export default function Image( {
const borderProps = useBorderProps( attributes );
const isRounded = attributes.className?.includes( 'is-style-rounded' );
const hasCustomBorder =
!! borderProps.className || ! isEmpty( borderProps.style );
!! borderProps.className ||
( borderProps.style && Object.keys( borderProps.style ).length > 0 );

let img = (
// Disable reason: Image itself is not meant to be interactive, but
Expand Down
7 changes: 4 additions & 3 deletions packages/block-library/src/image/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -31,15 +30,17 @@ export default function save( { attributes } ) {
title,
} = attributes;

const newRel = isEmpty( rel ) ? undefined : rel;
const newRel = ! rel ? undefined : rel;
const borderProps = getBorderClassesAndStyles( attributes );

const classes = classnames( {
[ `align${ align }` ]: align,
[ `size-${ sizeSlug }` ]: sizeSlug,
'is-resized': width || height,
'has-custom-border':
!! borderProps.className || ! isEmpty( borderProps.style ),
!! borderProps.className ||
( borderProps.style &&
Object.keys( borderProps.style ).length > 0 ),
} );

const imageClasses = classnames( borderProps.className, {
Expand Down
29 changes: 11 additions & 18 deletions packages/block-library/src/image/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* Internal dependencies
*/
Expand All @@ -11,21 +6,19 @@ import { NEW_TAB_REL } from './constants';
export function removeNewTabRel( currentRel ) {
let newRel = currentRel;

if ( currentRel !== undefined && ! isEmpty( newRel ) ) {
if ( ! isEmpty( newRel ) ) {
NEW_TAB_REL.forEach( ( relVal ) => {
const regExp = new RegExp( '\\b' + relVal + '\\b', 'gi' );
newRel = newRel.replace( regExp, '' );
} );
if ( currentRel !== undefined && newRel ) {
NEW_TAB_REL.forEach( ( relVal ) => {
const regExp = new RegExp( '\\b' + relVal + '\\b', 'gi' );
newRel = newRel.replace( regExp, '' );
} );

// Only trim if NEW_TAB_REL values was replaced.
if ( newRel !== currentRel ) {
newRel = newRel.trim();
}
// Only trim if NEW_TAB_REL values was replaced.
if ( newRel !== currentRel ) {
newRel = newRel.trim();
}

if ( isEmpty( newRel ) ) {
newRel = undefined;
}
if ( ! newRel ) {
newRel = undefined;
}
}

Expand Down

0 comments on commit 99c3dda

Please sign in to comment.