From 6d7aafa14c3e78ca7b4cded5da47b5f6b422191d Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Wed, 31 Aug 2022 14:14:21 +0300 Subject: [PATCH] Lodash: Remove completely from format-library package --- package-lock.json | 3 +-- packages/format-library/package.json | 3 +-- packages/format-library/src/link/index.native.js | 13 ++++++++++--- packages/format-library/src/text-color/index.js | 7 +------ .../format-library/src/text-color/index.native.js | 3 +-- packages/format-library/src/text-color/inline.js | 7 +------ 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index 77413a70d7913..adf7c39aa7c2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17431,8 +17431,7 @@ "@wordpress/i18n": "file:packages/i18n", "@wordpress/icons": "file:packages/icons", "@wordpress/rich-text": "file:packages/rich-text", - "@wordpress/url": "file:packages/url", - "lodash": "^4.17.21" + "@wordpress/url": "file:packages/url" } }, "@wordpress/hooks": { diff --git a/packages/format-library/package.json b/packages/format-library/package.json index 272ffa0462e3b..c700f6382339d 100644 --- a/packages/format-library/package.json +++ b/packages/format-library/package.json @@ -36,8 +36,7 @@ "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", "@wordpress/rich-text": "file:../rich-text", - "@wordpress/url": "file:../url", - "lodash": "^4.17.21" + "@wordpress/url": "file:../url" }, "peerDependencies": { "react": "^17.0.0", diff --git a/packages/format-library/src/link/index.native.js b/packages/format-library/src/link/index.native.js index d47862b77a58a..ed00450679c43 100644 --- a/packages/format-library/src/link/index.native.js +++ b/packages/format-library/src/link/index.native.js @@ -1,7 +1,6 @@ /** * External dependencies */ -import { find } from 'lodash'; import Clipboard from '@react-native-clipboard/clipboard'; /** @@ -86,13 +85,21 @@ export const link = { let startIndex = value.start; let endIndex = value.end; - while ( find( value.formats[ startIndex ], startFormat ) ) { + while ( + value.formats[ startIndex ].find( + ( format ) => format?.type === startFormat.type + ) + ) { startIndex--; } endIndex++; - while ( find( value.formats[ endIndex ], startFormat ) ) { + while ( + value.formats[ endIndex ].find( + ( format ) => format?.type === startFormat.type + ) + ) { endIndex++; } diff --git a/packages/format-library/src/text-color/index.js b/packages/format-library/src/text-color/index.js index 68783e4636254..bb0775b74ccde 100644 --- a/packages/format-library/src/text-color/index.js +++ b/packages/format-library/src/text-color/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { isEmpty } from 'lodash'; - /** * WordPress dependencies */ @@ -82,7 +77,7 @@ function TextColorEdit( { [ value, colors ] ); - const hasColorsToChoose = ! isEmpty( colors ) || ! allowCustomControl; + const hasColorsToChoose = colors.length || ! allowCustomControl; if ( ! hasColorsToChoose && ! isActive ) { return null; } diff --git a/packages/format-library/src/text-color/index.native.js b/packages/format-library/src/text-color/index.native.js index 8bba4fd25215d..5003dee86d3a5 100644 --- a/packages/format-library/src/text-color/index.native.js +++ b/packages/format-library/src/text-color/index.native.js @@ -1,7 +1,6 @@ /** * External dependencies */ -import { isEmpty } from 'lodash'; import { View } from 'react-native'; /** @@ -89,7 +88,7 @@ function TextColorEdit( { [ value, colors ] ); - const hasColorsToChoose = ! isEmpty( colors ) || ! allowCustomControl; + const hasColorsToChoose = colors.length || ! allowCustomControl; const onPressButton = useCallback( () => { if ( hasColorsToChoose ) { diff --git a/packages/format-library/src/text-color/inline.js b/packages/format-library/src/text-color/inline.js index 03a80fb18e687..ce8d4a43c14a4 100644 --- a/packages/format-library/src/text-color/inline.js +++ b/packages/format-library/src/text-color/inline.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; - /** * WordPress dependencies */ @@ -112,7 +107,7 @@ function setColors( value, name, colorSettings, colors ) { function ColorPicker( { name, property, value, onChange } ) { const colors = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); - return get( getSettings(), [ 'colors' ], [] ); + return getSettings().colors ?? []; }, [] ); const onColorChange = useCallback( ( color ) => {