diff --git a/.eslintrc.js b/.eslintrc.js index df395ada89fc0a..9cb0b100714d41 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -142,6 +142,7 @@ module.exports = { 'uniqueId', 'uniqWith', 'values', + 'words', 'zip', ], message: diff --git a/package-lock.json b/package-lock.json index b3d62a929efac9..6d7947ac5abc54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16506,6 +16506,7 @@ "@wordpress/url": "file:packages/url", "@wordpress/warning": "file:packages/warning", "@wordpress/wordcount": "file:packages/wordcount", + "change-case": "^4.1.2", "classnames": "^2.3.1", "colord": "^2.7.0", "diff": "^4.0.2", @@ -16515,6 +16516,7 @@ "react-autosize-textarea": "^7.1.0", "react-easy-crop": "^3.0.0", "rememo": "^4.0.0", + "remove-accents": "^0.4.2", "traverse": "^0.6.6" }, "dependencies": { diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index c817b8dd2b6f14..9b4f44e768336c 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -59,6 +59,7 @@ "@wordpress/url": "file:../url", "@wordpress/warning": "file:../warning", "@wordpress/wordcount": "file:../wordcount", + "change-case": "^4.1.2", "classnames": "^2.3.1", "colord": "^2.7.0", "diff": "^4.0.2", @@ -68,6 +69,7 @@ "react-autosize-textarea": "^7.1.0", "react-easy-crop": "^3.0.0", "rememo": "^4.0.0", + "remove-accents": "^0.4.2", "traverse": "^0.6.6" }, "peerDependencies": { diff --git a/packages/block-editor/src/components/inserter/search-items.js b/packages/block-editor/src/components/inserter/search-items.js index 1e3958b4853013..c2f8da7a6001b2 100644 --- a/packages/block-editor/src/components/inserter/search-items.js +++ b/packages/block-editor/src/components/inserter/search-items.js @@ -1,7 +1,9 @@ /** * External dependencies */ -import { deburr, find, words } from 'lodash'; +import { noCase } from 'change-case'; +import removeAccents from 'remove-accents'; +import { find } from 'lodash'; // Default search helpers. const defaultGetName = ( item ) => item.name || ''; @@ -21,7 +23,7 @@ const defaultGetCollection = () => null; function normalizeSearchInput( input = '' ) { // Disregard diacritics. // Input: "média" - input = deburr( input ); + input = removeAccents( input ); // Accommodate leading slash, matching autocomplete expectations. // Input: "/media" @@ -34,6 +36,17 @@ function normalizeSearchInput( input = '' ) { return input; } +/** + * Extracts words from an input string. + * + * @param {string} input The input string. + * + * @return {Array} Words, extracted from the input string. + */ +function extractWords( input = '' ) { + return noCase( input ).split( ' ' ).filter( Boolean ); +} + /** * Converts the search term into a list of normalized terms. * @@ -42,8 +55,7 @@ function normalizeSearchInput( input = '' ) { * @return {string[]} The normalized list of search terms. */ export const getNormalizedSearchTerms = ( input = '' ) => { - // Extract words. - return words( normalizeSearchInput( input ) ); + return extractWords( normalizeSearchInput( input ) ); }; const removeMatchingTerms = ( unmatchedTerms, unprocessedTerms ) => { @@ -150,7 +162,7 @@ export function getItemSearchRank( item, searchTerm, config = {} ) { category, collection, ].join( ' ' ); - const normalizedSearchTerms = words( normalizedSearchInput ); + const normalizedSearchTerms = extractWords( normalizedSearchInput ); const unmatchedTerms = removeMatchingTerms( normalizedSearchTerms, terms